|
我在.aspx中定义好了如下的datagrid,其中的asp:ButtonColumn列用于删除数据。
<asp:datagrid id="datagrid1" runat="server" AllowPaging="True" PageSize="8" AutoGenerateColumns="False" DataKeyField="zt_No" Width="100%" EnableViewState="false" PagerStyle-Visible="false" OnDeleteCommand="datagrid1_DeleteCommand" OnPageIndexChanged="datagrid1_PageIndexChanged">
<EditItemStyle Width="3px" BackColor="#FFFF80"></EditItemStyle>
<Columns>
<asp:BoundColumn DataField="zt_No" SortExpression="0" ReadOnly="True" HeaderText="编号"></asp:BoundColumn>
<asp:BoundColumn DataField="zt_name" SortExpression="2" ReadOnly="True" HeaderText="姓名"></asp:BoundColumn>
<asp:BoundColumn DataField="zt_sex" ReadOnly="True" HeaderText="性别"></asp:BoundColumn>
<asp:HyperLinkColumn DataNavigateUrlField="zt_No" DataNavigateUrlFormatString="xiugai.aspx?zt_No={0}" DataTextField="zt_No" HeaderText="详细信息" DataTextFormatString="修改"></asp:HyperLinkColumn>
<asp:ButtonColumn Text="删除" CommandName="Delete"></asp:ButtonColumn>
</Columns>
在.cs文件中的的delete事件定义如下:
protected void datagrid1_DeleteCommand(object source, DataGridCommandEventArgs e)
{
try
{
OleDbConnection cn = new OleDbConnection();
cn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("zt.mdb");
string str = "delete zt where zt_No=@zt";
OleDbCommand cm = new OleDbCommand(str, cn);
cm.Parameters.Add("@zt", OleDbType.Integer);
cm.Parameters["@zt"].Value = e.Item.Cells[0].Text.ToString();
cn.Open();
cm.ExecuteNonQuery();
cn.Close();
Bind();
}
catch (Exception ee)
{ Response.Write(ee.ToString()); }
}
经过测试,数据肯定删除不成功,同时也不提示有任何错误,我感觉是点删除后根本就没驱动事件处理!在线等高人解决问题!谢了 |
|