方法1:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lb = e.Row.FindControl("LinkButton1") as LinkButton;
lb.Attributes.Add("onclick", "return confirm('您真的要删除此行吗?')");
}
}
方法2: 添加OnClientClick事件 'return confirm("确认要删除吗?")'
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
OnClientClick='return confirm("确认要删除吗?")' Text="删除">
方法3:
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[2].Attributes.Add("onclick", "return confirm('确定删除吗?');");
}
方法4:
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemIndex >= 0 )
{
LinkButton lb = new LinkButton();
lb = (System.Web.UI.WebControls.LinkButton)e.Item.Cells[6].Controls[0];
lb.Attributes.Add("onclick","return window.confirm('你确定删除该记录吗?');");
}
}
方法5:
btnOk.Attributes.Add("onClick","if(document.all.rbtnDeleteSelect.checked==true)return confirm('您确定要删除吗?');");