Go to DotNetFunda.com
 Online : 637 |  Welcome, Guest!   Login
 
<<= Please see left side tutorials menu.

  • Download the OOPS, ASP.NET and ADO.NET online training sessions videos and related document for FREE, click here.


Silverlight Tutorials | Report a Bug in the Tutorial

Interesting?   Share and Bookmark this

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
413    
415231123432234
414ASDF
392bnbaaa
404cccc
411cbzcxzxvzxvzxv
391ccasaghjklghjkl 
397cincodasdasdadasdadsdasd
410dsfgfgsdfdg
401dzczcxzxczxczxczxxzczx
396gfhgfhgfgfhfgfghgf
400hhhh
407jfjfddjdjddjdjddjd
380Marakasadsfdsfdsfdsafdsafasdf
387Payalsdasa043364+ASSDS
416qwqweqweqwe
257rajchennai9942350800chennai
260raj123chennai9942350800chennai
369RajuHyd747473473hyd
374rgfsdfsdfgsdg
409rrrrrrrr
234rtyrrrrrrrrr
246ssss
376Sb732tempe
346SGGG
343ssss
398sadfsdfsdfsdfssdfssdfsdf
317sadxasdasdasd
324Sample345dfgdfg234324235cfgdfgdfg
226sangeethamadipakkam,PP22343223chennai
278sarveshusha1234567indore
334sdsdsdsd
254sdsdfsdfsd
379sdaasdf23234asdf
365sddghdhasdasdasd
315sdfsdfssfsdfsdfsd
290sdfsdfsdfsdf
277sdfsdfsdfsdf
340sdfsdfsfsdfdfsdfsdfsd
350sdfasdfasdfasdfa
378sdgsdfgsdfsfg
311SEEMADFCFERFERFRGFRE
345smHDS
302SovandyPhnom Penh017 855 431Phnom Penh
341srinusr nagar9703735834Hyd
250ssssss353656hyj
230ssssthtrhthtrhhrrthtrsdfsdfsd
244SSSSSIIIIIIIIdhh
402testtesttesttest
288TestTest12Testbxb
372testtesttesttest
274testtesttesttest
273testtesttesttest
314testtesttesttest
245thulasidelhi9988765433delhi
325try67567567
236tttttsdfasdf353453fasdfasdfad
247TYUTYUTYU  
348u8uuuuasdfasdfasdf
412Vahkirindia400067mumbai
342vidhyad3333dddd
395visahlnand 1234delhi
367vivekpune1234556oos
408vzxzxvzxzxvzx2352fsdfds
360werewrsdfsd45645645645
384wqwq3wq4wqwqwq
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 | The Team | Advertise | Contact Us | Feedback | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you found copied contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
All rights reserved to DotNetFunda.Com. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks.
(Best viewed in IE 6.0+ or Firefox 2.0+ at 1024 * 768 or higher)