2

我在这个 gridview 上有一个gridview, 和 a 。linkbutton

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

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

我找不到办法。

4

3 回答 3

7

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

OnClientClick="return confirm('Do you really want?');"
于 2012-03-16T16:49:48.077 回答
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?');");
}
于 2012-03-16T17:58:23.927 回答
0

in my code behind:

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

and in my markup:

<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> 
于 2016-09-15T23:08:53.033 回答