GridView删除列实现删除时确认对话框
好像很简单的样子,自己都不好意思贴了.
首先将CommandField(删除)列转换成模版列
其次在数据行绑定时写入下列代码.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//在服务器端添加删除确认
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton btnDelete = (LinkButton)e.Row.FindControl("LinkButton1");
btnDelete.Attributes.Add("onclick", "Javascript:return " +"confirm('Are you sure you want to delete this record " +DataBinder.Eval(e.Row.DataItem, "编号") + "')");
}
}