What you want to see on DotNetFunda.com ?
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 10193 |  Welcome, Guest!   Register  Login
Home > Tutorials > ASP.NET Tutorials > ObjectDataSource

Silverlight Tutorials | Report a Bug in the Tutorial
Found interesting? Add this to:


asp:ObjectDataSource control
ObjectDataSource enables user to define their own custom classes to bind data to the controls.
 
ObjectDataSource enables user to define their own custom classes to bind data to the controls. To use a class as an ObjectDataSource that class must have their own Insert, Delete, Update, and Select method. One important point that must be noted that ObjectDataSource doesn't support batch updation of the data, so the update method must support updation of the record one by one.

Some Important Properties of ObjectDataSource Control
InsertMethod, InsertParameters Gets or sets the name of the method and its parameter to perform insert operation.
UpdateMethod, UpdateParameters Gets or sets the name of the method and its parameter to perform update operation.
DeleteMethod, DeleteParameters Gets or sets the name of the method and its parameter to perform delete operation.
SelectMethod, SelectParameters Gets or sets the name of the method and its parameter to perform select operation.
ConvertNullToDBNull true/false. Used to indicate whether null parameter passed to the method should be converted to System.DBNull.
DataObjectTypeName Gets or sets the class name that is used to perform insert, update, delete, and select operation.
EnablePaging true/false. True if paging is supported by the method.
FilterExpression, FilterParameters Gets or sets the filter expression and filter parameter to filter the select operation.
SelectCountMethod Gets or sets the method name that is used to count the selected records (selected by SelectMethod method).
SortParameterName Gets or sets the name of the input parameter used to sort selected record.
StartRowIndexParameterName Works only if EnablePaging=true. Gets or sets the name of the parameter of select method that is used as starting record from where to retrieve records.
ConvertNullToDBNull true/false. Used to indicate whether null parameter passed to the method should be converted to System.DBNull.
DEMO : ObjectDataSource Show Source Code
AutoIDNameAddressPhoneCity
13351    
13349asdasdasdasd
13350asdfadfhgjghj
13330Fayazz14, Gandhi nagarjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjkkkkkkkkkkkkkkkkkkkkkkhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh96006091690Coimbatore
13335fdgfdfgdffd
13342Foo Testuio uio
13352hjh77
13331Johnok800ok
13333maya54 , lajpat nagar5890765delhi
13273pankajpatna8595392795patna
13336qwewqeqwewqe
13353rettertertttert
13318retreertretertretertretert
13310rewrttretreyrey
13313sddd
13315sddd
13329sadret567yuty
13341sadasdádasádasd
12621sasdtutyutsddartytrysdadrtyrtydsasartyry
13237sddfdfsdf
12735sdasdasdasdasdasdasd
13345sdasdasdasdasdasdasdasd
12825sddflklklklk
13275sdfasdfasfasf
13268sdfsdfdfdf
12671sdfsafsdfsdf
12643sdfsdfsdfsdf
12144sdfsdfsdfsdf
12837sdfdsafdsfdsfsdafdsfdas
13286sdffsdjk,hj6868kp;kvncnrf
12214sdfhadfghsdfgasdfgh
13029sdfsdsfsdfsdfsfsdfs
12653sdgsdfgsgsfgsdgsdfgsdg
13293sdgdfsdfsdfsdfsdf
13251sdgsdgsdgsdgsdsdggsd
12516sdmamdfd5656yyuy
13223sdqfdfqsdqsdfqfsdq
13224sdqfdfqsdqsdfqfsdq
13222sdqfdfqsdqsdfqfsdq
13225sdqfdfqsdqsdfqfsdq
13226sdqfdfqsdqsdfqfsdq
13220sdqfdfqsdqsdfqfsdq
13221sdqfdfqsdqsdfqfsdq
12340sdssdssddsd
12739sdsadaasdasdasdasdasasdasda
12338sdsdsdssdssds
12056sdsdsdsdssd
12707sdvcfererererererer
12901sdvdvvvcvcxxvvdsvdvdsdvdvsdv
13267sdvfbgvdsfvsfdgdsf
12228seds123sedssedsseds
12526sfdsfdfdf
12538sfsfsdfsdfsdfs
12268sfdsdfsdsdfsd
12130sfddsfsdsfsfsdfsfsdfsf
13163sfdssdfds7666dfffg
12082SFSDGsdfsdsdfsdsdf
12319shahsads65765765gdfdf
12313shahnawazalam8888888allahabad
12171shaikbangalore9987676543bangalore
12172shaikbangalore9987676543bangalore
12741shank12322333
12475ShankarnarayanShankarnarayanShankarnarayanShankarnarayan
12375shilpivikas 123456mathura
12661sibtainshah12-2---2karachi
12400sirilguntur 9988578960hyd
12417skindia00000000mm
12358skindia00000000MM
12921skahdhshdfsk212u30ansdkd
12133snahfhf858845chennai
12722snehasdfasdcascsacsac
13285snehakilpauk26432242chennai
12299sreetfd8888tnk
12810srihydernagar2738gurgan
12920Srinivasasdadsafd
12084srinuerrrt12233werr
12562srinubachibowli44444444444Hyderabad
12484sSsSsddeDDdfdD
12716sscc23432434cc
12306sssssssss
12703sssssssss
12910ssss7667ddssd
13119sssssssss
13192sssssssss
12374sssssssss
12344ssaasasasa
13020ssgdgqsfjdfgSDFSDasafagda
12964sssssss333dddd
13059sssssssssssssss
12405ssssssrrrrrrfffffaaaaa
12435stuart11212a city
12111subaskhkhhktoronto
12159subbufdffdffdf
12125subhashramnagar9457587589nsinital
12126subhashramnagar9457587589nsinital
13326Sudheer TankalaHno:10-5-134,Fathenagar09951627651Hyderabad
12556SunilSubhash Nagar9876543210Udaipur
12428Syed ZaidiAPT 811254558dallas
12211tttt
12163tttt
13193thfgh
12444t4t40gr
13032tdrtrtetretettret
12307tedtterer3434345346mum
13209tertertertreerter
12889Testtesttesttest
13076testtesttesttest
13069testtesttesttest
13274test   
12342testtesttesttest
12300TESTING905405940-9540909094MH
12298TESTING09403940349mum
12548testtestesttest
12549testtest234234sdfsdf
12293test123
12743testtesttesttest
12746testtesttesttest
13142testvitkin11234567net
12074testtestadress9586257fgfdhkj
12878testtesttesttest
12947testtesttesttest
13031testthishereok
13290testtesttesttest
13262testyyy
12482testtesttesttest
12561testtesttesttest
12480testtesttesttest
12129Test101sdfsdfsdfsdfsdfsdfsd
12576testetestetesteteste
12642testingawefawefaweffff
12170testttttttttestttttttttttttwattttttttwatttttt
12684tgyuynjikkiuhjnjnmyujnm v
13323ththfhtht
13322ththfhtht
12822ThantThiriMyoKyi
13212thulasi1247204744618bangalore
12410totoeee465465paris
12272trettretretretertretre
12626trhrtyrtyrtyrty
12713trytrydehi19875566441delhi
13231tsdhgdffdhg57445645645fg
13232tsdhgdffdhg57445645645fg
12220tttttttt
12221ttmit@testit.commit@testit.combb
13178ttrtgdfgdfgd9786786hfghf
13291tttttttttttt
12241tyrtrtyrtyrty
12242tyrtrtyrtyrty
12243tyrtrtyrtyrty
12244tyrtrtyrtyrty
12245tyrtrtyrtyrty
12246tyrtrtyrtyrty
12247tyrtrtyrtyrty
12248tyrtrtyrtyrty
12249tyrtrtyrtyrty
12250tyrtrtyrtyrty
12252tyrtrtyrtyrty
12253tyrtrtyrtyrty
13307tyutyuufghyugih
12852tyue5yu147q42s
13216tyutyututyututyu
13228tyyyghghg8585red
13087uiiu
12258u65u56uu56u56uaa
12485ueiADADDddDDd
12452ui9ojhhkjh
12778uikkghkkkyuyyy
13227uipyio[yio[yi[
12774ujwasdasdasd
12287UMASAH9766544
12263umair32321d12014521khi
12775ut6u67866786686
12059ututyuttyutuytyu66666vnfnhghfg
12365uuuuuuuuuuuu
12093uyfgyuguigugyugugugjbjhbjhbm
13120uyhukhgujfyt';ik';5645665  
13276uyyuyuyuyuyuuuyy
12809v1300 Elmwood AvegBuffalo
13300Varshalkabsklb898989898BANGALORE
12939vbsdvsdvsvsddsvsd
13325vbvvbnvbnvbn
13083venkatThi9000064443hyd
12162vffvffvvfvfvfvfvfv
12935vigneshpondy9962647896pondy
12970vigneshchennaioksdzkjhczjkchgoregoun
12229VijayPohwani6765669cbfhsdd
13338vijendrajaipur9950831083Jaipur
13337Vijendra Jaipur9950831083Jaipur
12460vishnusdfsdfsdf
12473vishnukafakg242964926sgfsk
12388vivekgfdg34455gbjg
12072vvvv11bnbn
12354vvvmmm256522bbb
12569vzvcxvxcvxcvcxvcxvcxvcxvx
12788wwww
12603wwww
13037wwwe
13080wwww
12560ww12www
13253watsthe F**is
12421wdwwewewewewewe
12985wer2rerwet24234234234fewrwerwe
13206wertwertwertwert
12179what is this87986283476testcity
12398wqasdasdads
12762wqeqwewqwewqeqwew
12372wqeqbjsbcsjbcnzbcnzxbcNXCBNZBC
13141wqeqweqweqweqweqweqwe
12453wrewerererwer
12537wrrewerwerwewrew
13000wwqweqwqweqwwew
13189wwwww   
12128xcxcvxcvxcv
12811xcxcsdsd
13343xczczcxc
12073xxxx111xx
12832xxxkbnjbkj jkj kj Ccjb SHC
12508xxxxxwwwwwww1ssssssssss
12436xxxxxxxxxxxxxx234234234
13112XYCewrwerwer324324234erwrwerwerwer
12122xzxxxxxxx
13287ytyuuu
12883yujr
12501yaduconocida1212121212sinaloa
12392yasartrichy22
12677yogeshpune9762738402pune
12359yttytytytytytytyyttytytyty
12531yuhhh
13150yuiuiuiYUIUH
13217yuiyuiyuiyuiyuiyyui
12790yuujukhkjhkjhkhjk
12180zahrafghfghfhfghgfhgfhgfhfg
12769ZCXzcZXCZXcXc
13035zdxdssdsd
13036zdxdssdsd
13134zz   
Parameter of SelectMethod
Show record WHERE AutoID greater than
                    
// GridView Control ///////////////////////////////
<asp:GridView ID="GridView1" DataSourceID="ObjectDataSource1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"
 PageSize="10">
    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    <EditRowStyle BackColor="#999999" />
    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>


// ObjectDataSource Control ///////////////////////////////
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
  TypeName="ObjectDataSourceSample" SelectMethod="Load">
  <SelectParameters>
    <asp:ControlParameter ControlID="txtGreater" PropertyName="Text" Name="greaterThan" Type="int32" />
  </SelectParameters>
</asp:ObjectDataSource>    
                       

// Parameter of SelectMethod ///////////////////////////////
Show record WHERE AutoID greater than <br />
<asp:TextBox ID="txtGreater" runat="Server" Text="3" Columns="5"></asp:TextBox>
<asp:CompareValidator ID="Cm" runat="server" ControlToValidate="txtGreater" Text="Numeric only" Display="Dynamic" Operator="DataTypeCheck" Type="integer"></asp:CompareValidator>
<asp:Button ID="btnSubmit" runat="Server" Text="Submit" />                       

    
    /// Load records ///////////////////////////////
    public DataSet Load(int greaterThan)
    {
        DataSet dSet = new DataSet();
        string connStr = ConfigurationManager.ConnectionStrings["ConectionString"].ToString();
        using (SqlConnection conn = new SqlConnection(connStr))
        {
            conn.Open();
            
            SqlDataAdapter dAd = new SqlDataAdapter("SELECT * FROM Sample WHERE AutoID > "+ greaterThan +" ORDER BY Name", conn);
            dAd.Fill(dSet, "SampleTable");
        }
        return dSet;
    }            
                    





About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/22/2013 1:49:57 AM