双击 gridview 的 RowDeleting 事件
在里面写上如下(参考)
string sqlstr = "delete from 表 where id='" +
GridView1.DataKeys[e.RowIndex].Value.ToString() + "'"; sqlcon = new
SqlConnection(strCon); sqlcom =
new SqlCommand(sqlstr,sqlcon);
sqlcon.Open();
sqlcom.ExecuteNonQuery();
sqlcon.Close();
bind();//数据绑定函数
在 bind 函数中加上
GridView1.DataKeyNames = new string[] { "id" };//主键
前台JS
后台代码
gridview 有一个RowDeleting 时间 在这个事件里面写
int UserID = Convert.ToInt32(GridView1.Rows[e.RowIndex].Cells[0].Text);//获取选中的行的ID
然后去数据库删除这条页面刷新一下就行了。