a.aspx <form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 208px" runat="server"
Width="728px" AutoGenerateColumns="False" HorizontalAlign="Center" Font-Size="12px">
<Columns>
<asp:BoundColumn DataField="LastName" HeaderText="LastName"></asp:BoundColumn>
<asp:BoundColumn DataField="FirstName" HeaderText="FirstName"></asp:BoundColumn>
<asp:BoundColumn DataField="Title" HeaderText="Title"></asp:BoundColumn>
<asp:BoundColumn DataField="HireDate" HeaderText="HireDate"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="动作">
<ItemTemplate>
<asp:HyperLink id="HyperLink1" Runat="server" NavigateUrl='<%# DataBinder.Eval(Container, "DataItem.LastName", "li.aspx?Action=Edit&ID={0}") %>' Text="编辑"></asp:HyperLink>|
<asp:LinkButton runat="server" Text="删除" CommandName="Delete" CausesValidation="false" ></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid></FONT>
</form>
a.aspx.csusing System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace WebApplication1
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
private SqlConnection conn;
private SqlCommand cmd;
private SqlDataAdapter da;
private DataTable dt;
private DataRowCollection dr;
private String connString;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private String strSQL;
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack) 
{
BindData();

else
{
BindData();
}
}
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) 

int _int = Convert.ToInt32(DataGrid1.DataKeys[e.Item.ItemIndex]); 
connString = "data source=localhost;uid=sa;pwd=;initial catalog=Northwind";
strSQL = "SELECT LastName, FirstName, Title, HireDate FROM dbo.Employees";
strSQL = "DELETE FROM dbo.Employees WHERE EmployeeID = " + _int; conn = new SqlConnection(connString); cmd = new SqlCommand(strSQL, conn); 
conn.Open(); 
cmd.ExecuteNonQuery(); 
BindData(); 

private void BindData()
{ connString = "data source=localhost;uid=sa;pwd=;initial catalog=Northwind";
strSQL = "SELECT LastName, FirstName, Title, HireDate FROM dbo.Employees";
try 
{
conn = new SqlConnection(connString);
cmd = new SqlCommand(strSQL, conn);
da = new SqlDataAdapter();
da.SelectCommand = cmd;
dt = new DataTable("axislover");
conn.Open();
da.Fill(dt);

DataGrid1.DataSource = dt;
DataGrid1.DataBind(); conn.Close();

catch (SqlException ex) 
{
Response.Write("Error accessing database: " + ex.ToString());

catch (Exception ex) 
{
Response.Write("Exception: " + ex.ToString());

finally 
{
if (conn.State == ConnectionState.Open) 
{
conn.Close();
}
conn.Dispose();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{    
this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{

}
}
}