删除按钮不起作用
我用的是在Datagrid中删除..但点击它不起作用..事件代码是:
public void stugrid_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{ Response.Write("lll");
if(stugrid.Items.Count==1)
{
if(stugrid.CurrentPageIndex!=0)
{
stugrid.CurrentPageIndex = stugrid.CurrentPageIndex-1;
}
}
stugrid.DataKeyField="time";
string id = this.stugrid.DataKeys[e.Item.ItemIndex].ToString(); //定义数据健,取得ID
SqlConnection con = new SqlConnection("server=(local);user id=sa;password=sql;database=datac;");
SqlCommand com = new SqlCommand("delete from datainfo where time=@time",con);
com.Parameters.Add ("@time",SqlDbType.DateTime ,10);
com.Parameters ["@time"].Value =id;
con.Open();
com.ExecuteNonQuery();
BindGrid();
}
在DATAGRID中:
<asp:datagrid id="stugrid" runat="server" AutoGenerateColumns="false" OnEditCommand="stugrid_Edit"
OnUpdateCommand="stugrid_Update" OnCancelCommand="stugrid_Cancel" OnButtonCommand="stugrid_DeleteCommand" >
列控件在上面的DATAGRID中,代码是:
<asp:ButtonColumn
ButtonType="LinkButton"
CommandName="Delete"
HeaderText="删除"
Text="删除"
Visible="True"/>