一、数据库Test,
表:create table Customers
(
CustId int IDENTITY(1,1) primary key,
CustName varchar(20) not null,
Address varchar(50),
Linkman varchar(20)
)
//insert into Cusomers values('ggg','xuzhou','zhangsan');
二、配置文件web.config
<?xml version="1.0"?>
<configuration>
<appSettings/>
<connectionStrings>
<add name="TestConnectionString" connectionString="Data Source=GONGCHL;Initial Catalog=Test;Persist Security Info=True;User ID=sa;Password=123" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true"/>
<authentication mode="Windows"/>
</system.web>
</configuration>
三、业务实体
using System;
using System.Collections.Generic;
using System.Text;
namespace com.Model
{
/// <summary>
/// 业务实体CustomerInfo
/// </summary>
[Serializable]
public class CustomerInfo
{
/// <summary>
/// 默认的构造函数
/// </summary>
public CustomerInfo() {}
/// <summary>
/// 有参数的构造函数
/// </summary>
/// <param name="custId">客户号</param>
/// <param name="custName">客户名称</param>
/// <param name="address">客户地址</param>
/// <param name="linkman">联系人</param>
public CustomerInfo(int custId, string custName, string address, string linkman)
{
this.custId = custId;
this.custName = custName;
this.address = address;
this.linkman = linkman;
}
private int custId;
public int CustId
{
get { return custId; }
set { custId = value; }
}
private string custName;
public string CustName
{
get { return custName; }
set { custName = value; }
}
private string address;
public string Address
{
get { return address; }
set { address = value; }
}
private string linkman;
public string Linkman
{
get { return linkman; }
set { linkman = value; }
}
}
}
四、数据访问层
类:SqlHelper
//===============================================================================
// .NET数据访问通用程序,来自Microsoft公司
// 更多信息参见
// http://msdn.microsoft.com/library/en-us/dnbda/html/daab-rm.asp
//===============================================================================
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
namespace com.DataAccess
{
/// <summary>
/// SqlHelper类提供很高的数据访问性能,
/// 使用SqlClient类的通用定义.
/// </summary>
public abstract class SqlHelper
{
//定义数据库连接串
public static readonly string ConnectionStringLocalTransaction = ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString;
//public
static readonly string ConnectionStringInventoryDistributedTransaction
=
ConfigurationManager.ConnectionStrings["SQLConnString2"].ConnectionString;
//public
static readonly string ConnectionStringOrderDistributedTransaction =
ConfigurationManager.ConnectionStrings["SQLConnString3"].ConnectionString;
//public
static readonly string ConnectionStringProfile =
ConfigurationManager.ConnectionStrings["SQLProfileConnString"].ConnectionString;
// 存贮Cache缓存的Hashtable集合
private static Hashtable parmCache = Hashtable.Synchronized(new Hashtable());
/// <summary>
/// 使用连接字符串,执行一个SqlCommand命令(没有记录返回)
/// 使用提供的参数集.
/// </summary>
/// <remarks>
/// 示例:
/// int result = ExecuteNonQuery(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
/// </remarks>
/// <param name="connectionString">一个有效的SqlConnection连接串</param>
/// <param name="commandType">命令类型CommandType(stored procedure, text, etc.)</param>
/// <param name="commandText">存贮过程名称或是一个T-SQL语句串</param>
/// <param name="commandParameters">执行命令的参数集</param>
/// <returns>受此命令影响的行数</returns>
public static int ExecuteNonQuery(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand cmd = new SqlCommand();
using (SqlConnection conn = new SqlConnection(connectionString))
{
PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
}
/// <summary>
/// 在一个存在的连接上执行数据库的命令操作
/// 使用提供的参数集.
/// </summary>
/// <remarks>
/// e.g.:
/// int result = ExecuteNonQuery(connection, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
/// </remarks>
/// <param name="conn">一个存在的数据库连接对象</param>
/// <param name="commandType">命令类型CommandType (stored procedure, text, etc.)</param>
/// <param name="commandText">存贮过程名称或是一个T-SQL语句串</param>
/// <param name="commandParameters">执行命令的参数集</param>
/// <returns>受此命令影响的行数</returns>
public static int ExecuteNonQuery(SqlConnection connection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
/// <summary>
/// 在一个事务的连接上执行数据库的命令操作
/// 使用提供的参数集.
/// </summary>
/// <remarks>
/// e.g.:
/// int result = ExecuteNonQuery(trans, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
/// </remarks>
/// <param name="trans">一个存在的事务</param>
/// <param name="commandType">命令类型CommandType (stored procedure, text, etc.)</param>
/// <param name="commandText">存贮过程名称或是一个T-SQL语句串</param>
/// <param name="commandParameters">执行命令的参数集</param>
/// <returns>受此命令影响的行数</returns>
public static int ExecuteNonQuery(SqlTransaction trans, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, commandParameters);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
/// <summary>
/// 在一个连接串上执行一个命令,返回一个SqlDataReader对象
/// 使用提供的参数.
/// </summary>
/// <remarks>
/// e.g.:
/// SqlDataReader r = ExecuteReader(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
/// </remarks>
/// <param name="connectionString">一个有效的SqlConnection连接串</param>
/// <param name="commandType">命令类型CommandType(stored procedure, text, etc.)</param>
/// <param name="commandText">存贮过程名称或是一个T-SQL语句串</param>
/// <param name="commandParameters">执行命令的参数集</param>
/// <returns>一个结果集对象SqlDataReader</returns>
public static SqlDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand cmd = new SqlCommand();
SqlConnection conn = new SqlConnection(connectionString);
// 如果不存在要查询的对象,则发生异常
// 连接要关闭
// CommandBehavior.CloseConnection在异常时不发生作用
try
{
PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
cmd.Parameters.Clear();
return rdr;
}
catch
{
conn.Close();
throw;
}
}
/// <summary>
/// 在一个连接串上执行一个命令,返回表中第一行,第一列的值
/// 使用提供的参数.
/// </summary>
/// <remarks>
/// e.g.:
/// Object obj = ExecuteScalar(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
/// </remarks>
/// <param name="connectionString">一个有效的SqlConnection连接串</param>
/// <param name="commandType">命令类型CommandType(stored procedure, text, etc.)</param>
/// <param name="commandText">存贮过程名称或是一个T-SQL语句串</param>
/// <param name="commandParameters">执行命令的参数集</param> /// <returns>返回的对象,在使用时记得类型转换</returns>
public static object ExecuteScalar(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand cmd = new SqlCommand();
using (SqlConnection connection = new SqlConnection(connectionString))
{
PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
object val = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return val;
}
}
/// <summary>
/// 在一个连接上执行一个命令,返回表中第一行,第一列的值
/// 使用提供的参数.
/// </summary>
/// <remarks>
/// e.g.:
/// Object obj = ExecuteScalar(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
/// </remarks>
/// <param name="connectionString">一个有效的SqlConnection连接</param>
/// <param name="commandType">命令类型CommandType(stored procedure, text, etc.)</param>
/// <param name="commandText">存贮过程名称或是一个T-SQL语句串</param>
/// <param name="commandParameters">执行命令的参数集</param> /// <returns>返回的对象,在使用时记得类型转换</returns>
public static object ExecuteScalar(SqlConnection connection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
object val = cmd.ExecuteScalar();
cmd.Parameters.Clear();
return val;
}
/// <summary>
/// 在缓存中添加参数数组
/// </summary>
/// <param name="cacheKey">参数的Key</param>
/// <param name="cmdParms">参数数组</param>
public static void CacheParameters(string cacheKey, params SqlParameter[] commandParameters)
{
parmCache[cacheKey] = commandParameters;
}
/// <summary>
/// 提取缓存的参数数组
/// </summary>
/// <param name="cacheKey">查找缓存的key</param>
/// <returns>返回被缓存的参数数组</returns>
public static SqlParameter[] GetCachedParameters(string cacheKey)
{
SqlParameter[] cachedParms = (SqlParameter[])parmCache[cacheKey];
if (cachedParms == null)
return null;
SqlParameter[] clonedParms = new SqlParameter[cachedParms.Length];
for (int i = 0, j = cachedParms.Length; i < j; i++)
clonedParms[i] = (SqlParameter)((ICloneable)cachedParms[i]).Clone();
return clonedParms;
}
/// <summary>
/// 提供一个SqlCommand对象的设置
/// </summary>
/// <param name="cmd">SqlCommand对象</param>
/// <param name="conn">SqlConnection 对象</param>
/// <param name="trans">SqlTransaction 对象</param>
/// <param name="cmdType">CommandType 如存贮过程,T-SQL</param>
/// <param name="cmdText">存贮过程名或查询串</param>
/// <param name="cmdParms">命令中用到的参数集</param>
private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, CommandType cmdType, string cmdText, SqlParameter[] cmdParms)
{
if (conn.State != ConnectionState.Open)
conn.Open();
cmd.Connection = conn;
cmd.CommandText = cmdText;
if (trans != null)
cmd.Transaction = trans;
cmd.CommandType = cmdType;
if (cmdParms != null)
{
foreach (SqlParameter parm in cmdParms)
cmd.Parameters.Add(parm);
}
}
}
}
类:Customer
using System;
using System.Data.SqlClient;
using System.Data;
using System.Text;
using System.Collections.Generic;
using com.Model;
namespace com.DataAccess
{
/// <summary>
/// 对客户表的所有数据访问操作
/// </summary>
public class Customer
{
//静态常量,参数名,T-SQL串
private const string SQL_SELECT_CUSTOMER_BY_ID =
"SELECT CustId, CustName, Address, Linkman FROM CUSTOMERS WHERE CustID = @CustId";
private const string SQL_SELECT_CUSTOMER_BY_NAME =
"SELECT CustId, CustName, Address, Linkman FROM CUSTOMERS WHERE CustName = @CustName";
private const string SQL_SELECT_CUSTOMER_BY_ALL =
"SELECT CustId, CustName, Address, Linkman FROM CUSTOMERS";
private const string SQL_UPDATE_CUSTOMER_BY_ID =
"UPDATE CUSTOMERS SET CustName=@CustName, Address=@Address, Linkman = @Linkman WHERE CustId=@CustId ";
private const string SQL_DELETE_CUSTOMER_BY_ID =
"DELETE CUSTOMERS WHERE CustId=@CustId ";
private const string SQL_INSERT_CUSTOMER =
"Declare @ID int;INSERT INTO CUSTOMERS VALUES(@CustName, @Address, @Linkman);SELECT @ID = @@IDENTITY; SELECT @ID";
private const string PARM_CUSTOMERID = "@CustId";
private const string PARM_CUSTOMERNAME = "@CustName";
private const string PARM_ADDRESS = "@Address";
private const string PARM_LINKMAN = "@Linkman";
/// <summary>
/// 按客户ID查询
/// </summary>
/// <param name="custId">客户号</param>
/// <returns>客户对象</returns>
public CustomerInfo GetCustomerById(int custId)
{
CustomerInfo customerInfo=null;
SqlParameter parm = new SqlParameter(PARM_CUSTOMERID, SqlDbType.Int);
parm.Value = custId;
//按客户号参数执行查询得到一个客户信息
using (SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_CUSTOMER_BY_ID, parm))
{
if (rdr.Read())
customerInfo = new CustomerInfo(rdr.GetInt32(0), rdr.GetString(1), rdr.GetString(2), rdr.GetString(3));
}
return customerInfo;
}
/// <summary>
/// 按客户名称查询
/// </summary>
/// <param name="custName">客户名称</param>
/// <returns>客户对象</returns>
public CustomerInfo GetCustomerByName(string custName)
{
CustomerInfo customerInfo = null;
SqlParameter parm = new SqlParameter(PARM_CUSTOMERNAME, SqlDbType.VarChar,20);
parm.Value = custName;
//按客户号参数执行查询得到一个客户信息
using (SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_CUSTOMER_BY_NAME, parm))
{
if (rdr.Read())
customerInfo = new CustomerInfo(rdr.GetInt32(0), rdr.GetString(1), rdr.GetString(2), rdr.GetString(3));
}
return customerInfo;
}
/// <summary>
/// 查询所有客户信息
/// 结果为IList
/// </summary>
/// <returns>一个客户集合</returns>
public IList<CustomerInfo> GetCusomersByAll()
{
IList<CustomerInfo> customers = new List<CustomerInfo>();
//Finally execute the query
using (SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_CUSTOMER_BY_ALL, null))
{
while (rdr.Read())
{
CustomerInfo customerInfo = new CustomerInfo(rdr.GetInt32(0), rdr.GetString(1), rdr.GetString(2), rdr.GetString(3));
customers.Add(customerInfo);
}
}
return customers;
}
/// <summary>
/// 插入一个客户信息
/// </summary>
/// <param name="customer">客户对象CustomerInfo</param>
/// <returns>bool类型,true or false</returns>
public bool InsertCustomer(CustomerInfo customerInfo)
{
SqlParameter[] paras = new SqlParameter[3];
paras[0]=new SqlParameter(PARM_CUSTOMERNAME,SqlDbType.VarChar,20);
paras[0].Value=customerInfo.CustName;
paras[1]=new SqlParameter(PARM_ADDRESS,SqlDbType.VarChar,50);
paras[1].Value=customerInfo.Address;
paras[2]=new SqlParameter(PARM_LINKMAN,SqlDbType.VarChar,20);
paras[2].Value=customerInfo.Linkman;
using (SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_INSERT_CUSTOMER, paras))
{
if (rdr.Read())
customerInfo.CustId = rdr.GetInt32(0);
else
return false;
}
return true;
}
/// <summary>
/// 修改一个客户信息
/// </summary>
/// <param name="customer">客户对象CustomerInfo</param>
/// <returns>bool类型,true or false</returns>
public bool UpdateCustomerByID(CustomerInfo customerInfo)
{
SqlParameter[] paras = new SqlParameter[4];
paras[0] = new SqlParameter(PARM_CUSTOMERNAME, SqlDbType.VarChar, 20);
paras[0].Value = customerInfo.CustName;
paras[1] = new SqlParameter(PARM_ADDRESS, SqlDbType.VarChar, 50);
paras[1].Value = customerInfo.Address;
paras[2] = new SqlParameter(PARM_LINKMAN, SqlDbType.VarChar, 20);
paras[2].Value = customerInfo.Linkman;
paras[3] = new SqlParameter(PARM_CUSTOMERID, SqlDbType.Int);
paras[3].Value = customerInfo.CustId;
int row = SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_UPDATE_CUSTOMER_BY_ID, paras);
if (row == 0)
return false;
return true;
}
/// <summary>
/// 按ID删除一个客户信息
/// </summary>
/// <param name="custId">客户号</param>
/// <returns>bool类型,true or false</returns>
public bool DeleteCustomerByID(int custId)
{
SqlParameter para = new SqlParameter(PARM_CUSTOMERID, SqlDbType.Int);
para.Value = custId;
int row = SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_DELETE_CUSTOMER_BY_ID, para);
if (row == 0)
return false;
return true;
}
}
}
五、业务逻辑层
using System;
using System.Collections.Generic;
using System.Text;
using com.DataAccess;
using com.Model;
using com.BusinessRule;
namespace com.BusinessLogic
{
public class CustomerLogic
{
/// <summary>
/// 插入一个客户信息
/// </summary>
/// <param name="custId">客户号</param>
/// <param name="custName">客户名称</param>
/// <param name="address">客户地址</param>
/// <param name="linkman">联系人</param>
/// <returns>bool类型,true or false</returns>
public bool InsertCustomer(int custId,string custName, string address, string linkman)
{
if (CustomerRule.IsExistCustomerName(custName))
return false;
Customer customer = new Customer();
CustomerInfo customerInfo = new CustomerInfo(custId,custName,address,linkman);
return customer.InsertCustomer(customerInfo);
}
/// <summary>
/// 插入一个客户信息
/// </summary>
/// <param name="custName">客户名称</param>
/// <param name="address">客户地址</param>
/// <param name="linkman">联系人</param>
/// <returns>bool类型,true or false</returns>
public bool InsertCustomer(string custName, string address, string linkman)
{
if (CustomerRule.IsExistCustomerName(custName))
return false;
Customer customer = new Customer();
CustomerInfo customerInfo = new CustomerInfo(0, custName, address, linkman);
return customer.InsertCustomer(customerInfo);
}
/// <summary>
/// 修改一个客户信息
/// </summary>
/// <param name="custId">客户号</param>
/// <param name="custName">客户名称</param>
/// <param name="address">客户地址</param>
/// <param name="linkman">联系人</param>
/// <returns>bool类型,true or false</returns>
public bool UpdateCustomer(int custId,string custName, string address, string linkman)
{
Customer customer = new Customer();
CustomerInfo customerInfo = new CustomerInfo(custId, custName, address, linkman);
return customer.UpdateCustomerByID(customerInfo);
}
/// <summary>
/// 按ID删除一个客户信息
/// </summary>
/// <param name="custId">客户号</param>
/// <returns>bool类型,true or false</returns>
public bool DeleteCustomerByID(int custId)
{
Customer customer = new Customer();
return customer.DeleteCustomerByID(custId);
}
/// <summary>
/// 查询所有客户信息
/// 结果为IList
/// </summary>
/// <returns>一个客户集合</returns>
public IList<CustomerInfo> GetCustomersByAll()
{
Customer customer = new Customer();
return customer.GetCusomersByAll();
}
}
}
六、业务规则层
using System;
using System.Collections.Generic;
using System.Text;
using com.DataAccess;
using com.Model;
namespace com.BusinessRule
{
/// <summary>
/// 检查客户信息的合法性
/// </summary>
public class CustomerRule
{
/// <summary>
/// 检查客户的名称是否已经存在
/// </summary>
/// <remarks>
/// e.g.:
/// bool exist =CustomerRule.IsExistCustomerName(custName);
/// </remarks>
/// <param name="custName">客户名称</param>
/// <returns>客户存在与否</returns>
public static bool IsExistCustomerName(string custName)
{
Customer cust = new Customer();
CustomerInfo custInfo = cust.GetCustomerByName(custName);
if (custInfo == null)
return false;
else
return true;
}
}
}
七、业务外观层
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using com.BusinessLogic;
using com.Model;
namespace com.BusinessFacade
{
/// <summary>
/// 为界面中Table处理数据
/// </summary>
public class CustomerTable
{
public static void SetTableData(Table table)
{
IList<CustomerInfo> list = new CustomerLogic().GetCustomersByAll();
AddRowHead(table);
foreach (CustomerInfo cust in list)
{
AddRow(table, cust);
}
}
private static void AddRowHead(Table table)
{
TableCell cell = new TableCell();
cell.Text = "Head";
TableRow row = new TableRow();
row.Cells.Add(cell);
table.Rows.Add(row);
}
private static void AddRow(Table table, CustomerInfo cust)
{
TableRow row = new TableRow();
TableCell cell1 = new TableCell();
cell1.Text = cust.CustId.ToString();
TableCell cell2 = new TableCell();
cell2.Text = cust.CustName;
TableCell cell3 = new TableCell();
cell3.Text = cust.Address;
TableCell cell4 = new TableCell();
cell4.Text = cust.Linkman;
row.Cells.Add(cell1);
row.Cells.Add(cell2);
row.Cells.Add(cell3);
row.Cells.Add(cell4);
table.Rows.Add(row);
}
}
}
八、界面层
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
InsertMethod="InsertCustomer" SelectMethod="GetCustomersByAll" TypeName="com.BusinessLogic.CustomerLogic" DeleteMethod="DeleteCustomerByID" UpdateMethod="UpdateCustomer">
<DeleteParameters>
<asp:ControlParameter ControlID="FormView1" PropertyName="SelectedValue" Name="custId" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="custId" Type="Int32" />
<asp:Parameter Name="custName" Type="String" />
<asp:Parameter Name="address" Type="String" />
<asp:Parameter Name="linkman" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="custName" Type="String" />
<asp:Parameter Name="address" Type="String" />
<asp:Parameter Name="linkman" Type="String" />
</InsertParameters>
</asp:ObjectDataSource>
<asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1" AllowPaging="True" DataKeyNames="custId">
<EditItemTemplate>
CustName:
<asp:TextBox ID="CustNameTextBox" runat="server" Text='<%# Bind("CustName") %>'></asp:TextBox><br />
Address:
<asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>'></asp:TextBox><br />
Linkman:
<asp:TextBox ID="LinkmanTextBox" runat="server" Text='<%# Bind("Linkman") %>'></asp:TextBox><br />
CustId:
<asp:TextBox ID="CustIdTextBox" runat="server" BorderStyle="None" Enabled="False"
Text='<%# Bind("CustId") %>'></asp:TextBox><br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
Text="更新"></asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="取消"></asp:LinkButton>
</EditItemTemplate>
<InsertItemTemplate>
CustName:
<asp:TextBox ID="CustNameTextBox" runat="server" Text='<%# Bind("CustName") %>'></asp:TextBox><br />
Address:
<asp:TextBox ID="AddressTextBox" runat="server" Text='<%# Bind("Address") %>'></asp:TextBox><br />
Linkman:
<asp:TextBox ID="LinkmanTextBox" runat="server" Text='<%# Bind("Linkman") %>'></asp:TextBox><br />
CustId:
<asp:TextBox ID="CustIdTextBox" runat="server" Text='0' Enabled="False"></asp:TextBox><br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
Text="插入"></asp:LinkButton>
<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="取消"></asp:LinkButton>
</InsertItemTemplate>
<ItemTemplate>
CustName:
<asp:Label ID="CustNameLabel" runat="server" Text='<%# Bind("CustName") %>'></asp:Label><br />
Address:
<asp:Label ID="AddressLabel" runat="server" Text='<%# Bind("Address") %>'></asp:Label><br />
Linkman:
<asp:Label ID="LinkmanLabel" runat="server" Text='<%# Bind("Linkman") %>'></asp:Label><br />
CustId:
<asp:Label ID="CustIdLabel" runat="server" Enabled="False" Text='<%# Bind("CustId") %>'></asp:Label><br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
Text="编辑"></asp:LinkButton>
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
Text="删除" ></asp:LinkButton>
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
Text="新建"></asp:LinkButton>
</ItemTemplate>
</asp:FormView>
<asp:Table ID="Table1" runat="server">
</asp:Table>
</form>
</body>