给定以下 GridView 代码:
<asp:GridView ID="gvReq" runat="server" DataSourceID="objdsReq" >
<Columns>
<asp:TemplateField HeaderText="Control">
<ItemTemplate>
<asp:LinkButton ID="lbdelete" runat="server" CommandArgument='<%# Container.DataItemIndex %>' ForeColor="Red" CommandName="DeleteReq">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="objdsReq" runat="server" SelectMethod="GetDataTable" >
<%-- parameter list --%>
</asp:ObjectDataSource>
在 RowDataBound 事件中,添加了 JavaScript 代码:
Protected Sub gvReq_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvReq.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Then
Dim lbdelete As LinkButton = e.Row.Cells(DELETE_CELL).Controls.Item(1)
lbdelete.Attributes.Add("onclick", "javascript:if(confirm('Are you sure you want to delete?')){return true}else{return false}")
JavaScript 触发,但 RowCommand 事件永远不会触发 - 我猜是因为它只由 JavaScript 处理:
Protected Sub gvReq_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles gvReq.RowCommand
Dim dataItemIndex As Integer = Convert.ToInt32(e.CommandArgument)
Dim reqID As Integer = Convert.ToInt32(gvReq.DataKeys(dataItemIndex).Values(0))
If e.CommandName = "DeleteReq" Then
JavaScript 确认对话框是按管理层的要求放在那里的。
OK
现在,如果有人单击JavaScript 确认框,我如何让 RowCommand 事件处理程序触发?