关于DataGrid添加删除确认对话框的问题
我给DataGrid添加了删除确认对话框后,不管是点确定还是取消,他都删除,大家帮忙看看是哪的问题,谢谢!
private void grd_User_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
switch(e.Item.ItemType)
{
case ListItemType.Item:
case ListItemType.EditItem:
case ListItemType.AlternatingItem:
LinkButton myDelButton = (LinkButton)e.Item.FindControl( "lbtn_Del ");
myDelButton.Attributes.Add( "onclick ", "return confirm( '删除该行将删除该行下所有用户\\n你真的要删除该行吗? '); ");
break;
}
private void grd_User_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
int UserID=Convert.ToInt32(this.grd_User.DataKeys[e.Item.ItemIndex]);
if(e.CommandName== "Edit ")
{
Response.Redirect( "User.aspx?Func=Edit&UserID= "+UserID);
}
if(e.CommandName== "Del ")
{
if(UserID==int.Parse(Session[ "UserID "].ToString()))
{
MessageBox.Show(this, "不能删除当前用户! ");
return;
}
else
{
//删除代码
MessageBox.Show(this, "删除成功! ");
}
}
}
------解决方案--------------------直接拷我的代码来了,前面一段不要看了,进行数据收集的
string script = "var thisfrm = document.forms[0]; ";
script += "for (i=0; i <thisfrm.elements.length; i++){ ";
script += "if (thisfrm.elements[i].name.indexOf( 'chk ') !=-1){ ";
script += "if(thisfrm.elements[i].checked) ";
script += "{return confirm ( '是否确认要删除该数据? ');break;}}} ";
script += "alert( '请选择要删除的作业类型! ');return false; ";
DelBtn.Attributes.Add( "onclick ",script);