Creating a Customer class to demonstrate the ObjectDataSource control (C#) : ObjectDataSource « ADO.net Database « ASP.NET Tutorial






<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
       <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DeleteMethod="Delete"
            InsertMethod="Insert" SelectMethod="Select" TypeName="Customer"
            UpdateMethod="Update">
            <SelectParameters>
                <asp:QueryStringParameter Name="customerID" QueryStringField="ID"
                    Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>
    </div>
    </form>
</body>
</html>

File: App_Code\Customer.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public class Customer
{
    private int _customerID;
    private string _companyName;
    private string _contactName;
    private string _contactTitle;

    public int CustomerID
    {
        get
        {
            return _customerID;
        }

        set
        {
            _customerID = value;
        }
    }

    public string CompanyName
    {
        get
        {
            return _companyName;
        }

        set
        {
            _companyName = value;
        }
    }

    public string ContactName
    {
        get
        {
            return _contactName;
        }

        set
        {
            _contactName = value;
        }
    }

    public string ContactTitle
    {
        get
        {
            return _contactTitle;
        }

        set
        {
            _contactTitle = value;
        }
    }

    public Customer()
    {
    }

    public System.Data.DataSet Select(Int32 customerId)
    {
        // Implement logic here to retrieve the Customer 
        // data based on the methods customerId parameter

        System.Data.DataSet ds = new System.Data.DataSet();
        ds.Tables.Add(new System.Data.DataTable());
        return ds;
    }

    public void Insert(Customer c)
    {
        // Implement Insert logic
    }

    public void Update(Customer c)
    {
        // Implement Update logic
    }

    public void Delete(Customer c)
    {
        // Implement Delete logic
    }

}








18.36.ObjectDataSource
18.36.1.Using ObjectDataSource
18.36.2.Using two ObjectDataSource controls in one page
18.36.3.ObjectDataSource binds DataBound controls such as the GridView, DetailsView, and FormView controls to a component
18.36.4.Bind SqlDataReader with asp:ObjectDataSource
18.36.5.Binding to a DataSet
18.36.6.asp:ObjectDataSource with UpdateParameters
18.36.7.Paging, Sorting, and Filtering Data with the ObjectDataSource Control
18.36.8.ObjectDataSource Update
18.36.9.ObjectDataSource Insert
18.36.10.Creating a Customer class to demonstrate the ObjectDataSource control (C#)
18.36.11.Creating a Customer class to demonstrate the ObjectDataSource control (VB)