删除gridview中的记录
怎么实现删除gridview中的记录,请教了?
------解决方案--------------------protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
{//删除
int i = int.Parse(GridView2.DataKeys[e.RowIndex].Value.ToString());
infos.deleteinfotype(i);//传递要删除的记录ID到SQL语句
// infotypeload();
// Message.Show(this, "a ", "删除成功 ");
Response.Write( " <script language= 'javascript '> alert( '删除成功! '); </script> ");
}
------解决方案--------------------1、绑定datagrid的时候,保存key
this.DataGrid1.DataKeyField= "id ";
2、datagrid的删除事情
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
//获得删除行的key id
int id=this.DataGrid1.DataKeys[e.Item.ItemIndex];
//接下来应该不用说了....
}