当前位置:编程学习 > C#/ASP.NET >>

求助gridview自带的删除,弹出提示框问题。困惑很多天了

网上看过很多方法。都不能用。因为自带的编辑、删除按钮同在一列里,无法转为模版列。

刚刚用了这个办法,但也不行,帮我看看是什么原因。

先自定义了一个过程:
 Private Function delmsg() As Boolean
        Response.Write("<script language='javascript'>confirm('确定要删除吗?'); </script>")
 End Function

然后在Protected Sub GridView1_RowDeleting事件里调用:
Dim Strdel As String = delmsg().ToString
       If Strdel = "False" Then
            Exit Sub
        Else
          ....删除代码

我的编辑、删除、选择3个按钮是在最左边的同一列里的,请问什么办法能弹出提示框。 --------------------编程问答-------------------- 在前台代码各自的标签中加onClientClick(好像是这个)事件,里面写个js脚本。比如:return confirm('确定要删除吗?'); ,就可以了。 --------------------编程问答--------------------  protected void Gvck_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "currColor=this.style.backgroundColor; this.style.backgroundColor='#ccccff';");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currColor");
            e.Row.Cells[4].Attributes.Add("onclick", "return confirm('你确定要删除吗?')");
        }    
    }

我这是.net的 你就改成 vb的试试吧  e.row.cells[4] 这个是删除按钮所在列。 --------------------编程问答-------------------- 我的删除按钮和编辑、选择都在第一列 --------------------编程问答-------------------- 2楼的方法不可以吗? --------------------编程问答-------------------- 2楼的方法删除按钮在第四列。而我的删除按钮是在代码里加的。因为我要根据权限隐藏或可视删除按钮。

如果在编辑列里添加删除按钮并转为模版列,再添加LinkButton1。如ID="LinkButton1"

则在后台无法获取LinkButton1。没法设置LinkButton1的隐藏或可视 --------------------编程问答-------------------- 方法是有,让删除这一列隐藏。

但是,我将显示表格是写了一个自定义过程了,按权限显示或隐藏删除按钮。

每次有操作更新绑定后都要调用该过程。在gridview_RowCreated事件里隐藏删除列,但我在其他过程里无

法调用gridview_RowCreated。比如编辑更新以后,我要调用那个显示过程,GRIDVIEW表格才会显示出来,

否则就看不到表格。 --------------------编程问答--------------------
引用 5 楼  的回复:
2楼的方法删除按钮在第四列。而我的删除按钮是在代码里加的。因为我要根据权限隐藏或可视删除按钮。

如果在编辑列里添加删除按钮并转为模版列,再添加LinkButton1。如ID="LinkButton1"

则在后台无法获取LinkButton1。没法设置LinkButton1的隐藏或可视


可以试试e.Row.FindControl(""); --------------------编程问答-------------------- 楼主问的是ASP.NET的问题吗? --------------------编程问答-------------------- 2楼的能行的 --------------------编程问答--------------------   /// <summary>
    /// 隐藏不需要的列
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        Utility.Utility.AlternateRowColor (e);
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (UserNameRole()!= 1)//如果方法的返回值 符合权限
            {
                (e.Row.Cells[20].FindControl("lnkBtnupdate") as LinkButton).Enabled = false;//这个 控件 就隐藏
            }
            else
            {
                (e.Row.Cells[20].FindControl("lnkBtnupdate") as LinkButton).Enabled = true;//显示
            }
        }
    } --------------------编程问答-------------------- 改下 :Enabled 改为 Visible. --------------------编程问答-------------------- 楼主 可以把 后台写的控件 直接绑定在Gridview里面啊  然后这样 通过权限控制这个控件是否显示。我这里也是这么一个功能。
/// <summary>
  /// 隐藏不需要的列
  /// </summary>
  /// <param name="sender"></param>
  /// <param name="e"></param>
  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  {
  Utility.Utility.AlternateRowColor (e);
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
  if (UserNameRole()!= 1)//如果方法的返回值 不符合权限
  {
  (e.Row.Cells[20].FindControl("lnkBtnupdate") as LinkButton).Enabled = Visible;//这个 控件 就隐藏
  }
  else
  {
  (e.Row.Cells[20].FindControl("lnkBtnupdate") as LinkButton).Enabled = Visible;//显示
  }
  }
  }
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,