0

在gridview 中,我有一个模板列,其中有一个linkBut​​ton 列。单击链接按钮列时,它会触发客户端,如果为 TRUE,则应调用服务器端事件。但不知何故,在这两种情况下都调用了服务器端事件 - TRUE 或 FALSE。请让我知道,如果我错过了什么......

标记代码如下 -

<asp:TemplateField HeaderText="Disable/Enable" ItemStyle-Width="10%"  HeaderStyle-HorizontalAlign="Left"#
    <ItemTemplate>
        <asp:LinkButton runat="server" ID="ableDisableLaborCode" CommandName="linkButtonClick" CommandArgument='#%# Eval("coLaborCodeID") %#'##/asp:LinkButton#
    </ItemTemplate>
</asp:TemplateField>

这是注册客户端事件的地方

Private Sub gridVwCoLaborCodes_RowDataBound(sender As Object, e As     System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridVwCoLaborCodes.RowDataBound
    If (e.Row.RowType = DataControlRowType.DataRow) Then
        Dim _lnk As LinkButton = DirectCast(e.Row.FindControl("ableDisableLaborCode"), LinkButton)
        Dim _drv As DataRowView = DirectCast(e.Row.DataItem, DataRowView)
        _lnk.Text = If(CBoolBit(_drv(Fields.NAME_FIELD_IS_ENABLED_FLAG)), "Disable", "Enable")
        _lnk.OnClientClick = String.Format("return confirm('Are you sure you want to deactivate this labor code ?');")
    End If
End Sub

以下是服务器端事件的代码——

Private Sub gridVwCoLaborCodes_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gridVwCoLaborCodes.RowCommand
    If e.CommandName = "linkButtonClick" Then
        CoLaborCodeId = CIntNull(e.CommandArgument.ToString())
    End If
End Sub

感谢所有查看和帮助。

4

1 回答 1

1

尝试以不同的方式分配 javascript 事件:

Private Sub gridVwCoLaborCodes_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridVwCoLaborCodes.RowDataBound
    If (e.Row.RowType = DataControlRowType.DataRow) Then
        Dim _lnk As LinkButton = DirectCast(e.Row.FindControl("ableDisableLaborCode"), LinkButton)
        Dim _drv As DataRowView = DirectCast(e.Row.DataItem, DataRowView)
        _lnk.Attributes.Add("onclick", "return confirm('Are you sure you want to deactivate this labor code ?');")
        lnk.Text = If(CBoolBit(_drv(Fields.NAME_FIELD_IS_ENABLED_FLAG)), "Disable", "Enable")
    End If
End Sub
于 2012-10-25T21:31:36.987 回答