行命令激发前Gridview中LinkButton的确认框
本文关键字:LinkButton 确认 Gridview 命令 | 更新日期: 2023-09-27 18:27:58
我在这个网格视图上有一个gridview
和linkbutton
。
当点击链接按钮时,rowCommand
会启动,但我想请用户用确认框确认点击
- 如果是->rowCommand激发
- 如果没有->什么都不会发生
我找不到它的方法。
将其添加为LinkButton的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>