在datagrid中,我添加了一列用来删除的按钮列,当点击后我要弹出一个(confirm)对话框
代码中 我要怎么写呢???
大哥大姐们 帮帮忙吧  已经郁闷了很久了……
等待中……

解决方案 »

  1.   


    //删除时绑定提示脚本,datagrid的ItemDataBound事件
    private void dgDept_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if (e.Item.ItemIndex>=0)
    {
    LinkButton lib=(LinkButton)e.Item.Cells[6].Controls[0]; // 6,按钮列的索引

    lib.Attributes.Add("onclick","javascript:return confirm('你确定要删除该部门信息吗?');"); }
    }
      

  2.   

    private void accountgrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemIndex>=0)
    {
    e.Item.Attributes.Add("onmouseover","this.style.backgroundColor='#FFC080'"); 
    e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#ffffff'");
    LinkButton delBttn = (LinkButton) e.Item.Cells[9].Controls[0]; 
    delBttn.Attributes.Add("onclick","javascript:return confirm('确定删除该条信息吗?');");  }
    }
      

  3.   

    private void subgrid_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    if(e.Item.ItemIndex>=0)
    {
        SqlConnection conn = new SqlConnection(ConfigManager.CurrentDBContext.ConnectionString);
    string id=e.Item.Cells[13].Text.ToString();
    string delSql="delete employee_subchange where id="+int.Parse(id)+"";
    System.Data.SqlClient.SqlCommand mycomm=new SqlCommand(delSql,conn);
    try
    {
    conn.Close();
    conn.Open();
    mycomm.ExecuteNonQuery(); }
    catch(Exception ex)
    {
    this.Response.Write(ex);
    }
    finally
    {
        conn.Close();
    mycomm.Dispose();
    }
    this.SubBind(bindSql2); 
    }
    }
      

  4.   

    wubike(xiaolei)
    出错了:指定的转换无效
    LinkButton lib=(LinkButton)e.Item.Cells[6].Controls[0]; // 6,按钮列的索引
    这句错误了
      

  5.   

    弹出的(confirm)对话框 
    点击了OK后要执行的代码要写在哪里的啊?
    答者都给分
      

  6.   

    点击确定按钮就会执行:Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand
        ....'你的删除代码
     End Sub
      

  7.   

    如楼上的所说,会自动执行
    e.Item.Cells[6].FindControl("控件ID");    //用这个试试