GridView实现删除时弹出确认对话框

//GridView实现删除时弹出确认对话框  
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)  
{  
    //GridView实现自动编号:  
    //注意这时最好把前台的第一列的表头该为“编号”,因为以前的第一列被“吃掉”了。  
    //if (e.Row.RowIndex != -1)  
    //{  
    //    int id = e.Row.RowIndex + 1;  
    //    e.Row.Cells[0].Text = id.ToString();  
    //}  
 
    //如果是绑定数据行   
    if (e.Row.RowType == DataControlRowType.DataRow) //如果行的类别是数据行,就执行  
    {  
        if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate || e.Row.RowState == DataControlRowState.Selected)  
        {  
          //((LinkButton)e.Row.Cells[13].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:ID号为/" " + e.Row.Cells[0].Text.ToString().Trim() + " /"的员工档案吗?')");  
          ((LinkButton)e.Row.Cells[13].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:姓名为/" " + e.Row.Cells[1].Text.ToString().Trim() + " /"的员工档案吗?')");  
 
        }  
    }  

    //GridView实现删除时弹出确认对话框
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //GridView实现自动编号:
        //注意这时最好把前台的第一列的表头该为“编号”,因为以前的第一列被“吃掉”了。
        //if (e.Row.RowIndex != -1)
        //{
        //    int id = e.Row.RowIndex + 1;
        //    e.Row.Cells[0].Text = id.ToString();
        //}

        //如果是绑定数据行
        if (e.Row.RowType == DataControlRowType.DataRow) //如果行的类别是数据行,就执行
        {
            if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate || e.Row.RowState == DataControlRowState.Selected)
            {
              //((LinkButton)e.Row.Cells[13].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:ID号为/" " + e.Row.Cells[0].Text.ToString().Trim() + " /"的员工档案吗?')");
              ((LinkButton)e.Row.Cells[13].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:姓名为/" " + e.Row.Cells[1].Text.ToString().Trim() + " /"的员工档案吗?')");

            }
        }
    }

注意:e.Row.Cells[1].Text.ToString().Trim() 这里的列一定要是 BoundField

如<asp:BoundField DataField="User_name" HeaderText="姓名" />

而不能是TemplateField 或 HyperLinkField 这些都不会显示出姓名!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值