|
I defined the following datagrid in .aspx, where the asp: ButtonColumn column is used to delete data.
<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 = "number"> </ asp: BoundColumn>
<asp: BoundColumn DataField = "zt_name" SortExpression = "2" ReadOnly = "True" HeaderText = "Name"> </ asp: BoundColumn>
<asp: BoundColumn DataField = "zt_sex" ReadOnly = "True" HeaderText = "Gender"> </ asp: BoundColumn>
<asp: HyperLinkColumn DataNavigateUrlField = "zt_No" DataNavigateUrlFormatString = "xiugai.aspx? zt_No = {0}" DataTextField = "zt_No" HeaderText = "Details" DataTextFormatString = "Modify"> </ asp: HyperLinkColumn>
<asp: ButtonColumn Text = "Delete" CommandName = "Delete"> </ asp: ButtonColumn>
</ Columns>
The delete event in the .cs file is defined as follows:
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 ());}
}
After testing, the data must be deleted unsuccessfully, and there are no errors, and I feel that after the point is deleted, the event processing is not driven at all! Online experts solve problems! Thanks |
|