| |
18. 36. 10. Creating a Customer class to demonstrate the ObjectDataSource control (C#) |
|
<!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
}
}
|
|
|