编辑
在gridview的rowDataBound事件中附加javascript单击功能最安全,最简单的方法...代码如下
protected void GridView1_RowDataBond(object source, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button btnAlertStatus = (Button)e.Row.FindControl("btnAlertStatus");
DataRowView drv = (DataRowView)e.Row.DataItem;
string username = drv["User_name"].ToString();
btnAlertStatus.Attributes.Add("onclick", "return confirm('Are you sure you want to delete this record?"+ username + "')"); //error because of javascript left one bracket
}
}
预
尝试
JavaScript
function confirmMsg()
{
var Variable = '<%= ServerVaraible %>';
return confirm('Are you sure you want to delete this record?'+ Variable );
}
HTML
<asp:Button id="btnDelete" runat="server" class="deleteicon" Text='<%# Eval("iuser_id") %>' OnClick="deleteclick" onclientclick="return confirmMsg();"/>