protected void UniGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
ImageButton deluser = (ImageButton) UniGridView.Rows[e.RowIndex].FindControl("ImageButton2");
deluser.OnClientClick = "return confirm(" + GetGlobalResourceObject("LocalizedText", "User_GridViewActionsDeleteConfirmation").ToString() + ")";
int index=e.RowIndex ;
GridViewRow gvr=UniGridView.Rows[index];
string userName = gvr.Cells[1].Text;
User currentUser2 = new User(userName);
currentUser2.Delete();
UniGridView_DataBind();
}
{
ImageButton deluser = (ImageButton) UniGridView.Rows[e.RowIndex].FindControl("ImageButton2");
deluser.OnClientClick = "return confirm(" + GetGlobalResourceObject("LocalizedText", "User_GridViewActionsDeleteConfirmation").ToString() + ")";
int index=e.RowIndex ;
GridViewRow gvr=UniGridView.Rows[index];
string userName = gvr.Cells[1].Text;
User currentUser2 = new User(userName);
currentUser2.Delete();
UniGridView_DataBind();
}
deluser.OnClientClick = "return confirm(" + GetGlobalResourceObject("LocalizedText", "User_GridViewActionsDeleteConfirmation").ToString() + ")";
这一句应在窗体Load的时候就应执行了,你在RowDeleting才有好像太晚了。
{
ImageButton deluser = (ImageButton)e.Row.FindControl("ImageButton2");
string js = "javascript:return confirm(" + GetGlobalResourceObject("LocalizedText", "User_GridViewActionsDeleteConfirmation").ToString() + ")";
deluser.Attributes.Add("onclick", js);
}
出错:未将对象引用设置到对象的实例,在deluser.Attributes.Add("onclick", js);
ImageButton deluser =(ImageButton)e.Item.FindControl("ImageButton2") ;
string js = "<script language='javascript'>return confirm(" + GetGlobalResourceObject("LocalizedText", "User_GridViewActionsDeleteConfirmation").ToString() + ")</script>");
if(deluser!=null)
{
deluser.Attribute.Add("onclick", js);
}
{
ImageButton deluser = (ImageButton)e.Row.FindControl("ImageButton2");
string js = "javascript:return confirm(" + GetGlobalResourceObject("LocalizedText", "User_GridViewActionsDeleteConfirmation").ToString() + ")";
deluser.Attributes.Add("onclick", js);
}
你這句話會出錯是因為你沒有判斷是不是數據行,如果是表頭是找不到那個按鈕的,所以你要么判斷當前行是否是數據行要么判斷取得的ImageButton是否為空
private void dg_ddl_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Button delete = (Button)e.Item.FindControl("btnDel");
delete.Attributes.Add("onclick", "return confirm('您真的要删除吗?');");
}
}
{
return;
}
<tr>
<td>
<asp:Button ID="btn_DelClass" runat="server" CommandArgument='<%# Eval("[\"BoardID\"]")%> ' CommandName="DelBoard" Text="× 删除版块" OnClientClick="return confirm('确实删除版块吗?删除版块会清除版块下的所有帖子!')"/>
</td>
</tr>
</ItemTemplate>
取不出来啊,否则倒好办了