要注意 :事件的参数类型如GridViewDeleteEventArgs 、GridViewRowEventArgs;把数据库链接和表名做适当的处理.
前台:OnRowDeleting ="GridView1_OnRowDeleting" OnRowCreated="GridView1_RowCreated"
后台:
protected void GridView1_OnRowDeleting(object sender, GridViewDeleteEventArgs e)
{
int id = Convert.ToInt32 ( GridView1.DataKeys[e.RowIndex].Value);//获得要删除行的id
//数据库操作,最好用存储过程
string DeleteCommand;
DeleteCommand = "delete 表名 where SDBP_MID='" +id +"'";
GridViewBind(DeleteCommand , "表名");
//重新绑定gridview
string sqlstr = "select * from 表名";
GridViewBind(sqlstr, "表名");
}
protected void GridView1_RowCreated(object sender,