c# GridView中,如何在后台添加删除列放在最后一列,并且有确认删除的提醒?

2025-03-23 05:10:58
推荐回答(3个)
回答1:

实现方法:
双击GridView的OnRowDataBound事件;
在后台的GridView1_RowDataBound()方法添加代码,最后代码如下所示:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//如果是绑定数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[1].Text + "\"吗?')");
}
}

}

回答2:

不知道能不能看看你的代码?一般就是在Gridview最后一行添加删除列就行了,然后在删除按钮上加个OnClientClick="return confirm('您确认删除记录?');"

回答3:

这个你可以自己定义,也可以用它模板自带的删除,然后给添加一个属性/事件就OK了。