繁体   English   中英

在Rowcommand触发之前GridView中LinkBut​​ton的确认框

[英]Confirmation box for LinkButton in Gridview before Rowcommand fires

我有一个gridview ,以及这个gridview上的一个linkbutton

当单击rowCommand时, rowCommand会触发,但是我想让用户通过确认框确认点击,

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

我找不到办法。

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

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

尝试这个。

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?');");
}

在我的代码背后:

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> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM