【问题标题】:Confirmation box for LinkButton in Gridview before Rowcommand fires在 Rowcommand 触发之前,Gridview 中的 LinkBut​​ton 的确认框
【发布时间】:2012-04-02 05:31:36
【问题描述】:

我在这个网格视图上有一个gridview 和一个linkbutton

点击链接按钮时,rowCommand 会触发,但是我想要求用户使用确认框确认点击,

  • 如果是 -> rowCommand 触发,
  • 如果没有 -> 没有任何反应。

我找不到办法。

【问题讨论】:

    标签: c# asp.net gridview dialog rowcommand


    【解决方案1】:

    将此添加为 LinkBut​​ton 的 OnClientClick 属性:

    OnClientClick="return confirm('Do you really want?');"
    

    【讨论】:

      【解决方案2】:

      试试这个。

      if (e.Row.RowType == DataControlRowType.DataRow){  
       LinkButton link = (LinkButton)e.Row.FindControl("LinkButton1");    
       link .Attributes.Add("onclick", "return confirm('Are you sure to proceed with this 
      action?');");
      }
      

      【讨论】:

        【解决方案3】:

        在我后面的代码中:

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton del = e.Row.Cells[2].Controls[0] as LinkButton;
            del.Attributes.Add("onclick", "return confirm('Are you sure you want to delete this role?');");
        }
        

        在我的标记中:

        <asp:GridView
            ID="GridViewRoles"
            runat="server"
            Width="350px"
            EmptyDataText="No Roles"
            AutoGenerateColumns="False"
            AllowPaging="False"
            PageSize="50"
            AllowSorting="True"
            CssClass="gridview"
            AlternatingRowStyle-CssClass="even"
            OnRowCommand="GridViewRoles_RowCommand"
            OnRowDataBound="GridViewRoles_RowDataBound"
            OnRowDeleting="GridViewRoles_RowDeleting" OnRowEditing="GridViewRoles_RowEditing">
            <Columns>
        
                <asp:BoundField DataField="Role" HeaderText="Role" SortExpression="Role" HeaderStyle-Width="170px" HeaderStyle-HorizontalAlign="Left" />
                <asp:ButtonField CommandName="Edit" Text="Edit" HeaderStyle-Width="50px" />
                <asp:CommandField ShowDeleteButton="True" />
        
            </Columns>
            <AlternatingRowStyle CssClass="even" />
        </asp:GridView> 
        

        【讨论】:

          猜你喜欢
          • 2017-09-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-12
          • 2011-06-19
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多