GridView中的OnClick过程的子例程未执行

时间:2012-09-29 12:09:16

标签: asp.net vb.net gridview onclick

我们有一个带有2个按钮的GridView。其中一个按钮是选择按钮,另一个是没有命令的按钮。它应该激活OnClick子例程。子例程没有执行。

以下是带有按钮的GridView标记:

        <asp:GridView
            ID="GridViewParentsSummary" 
            runat="server" 
            AllowPaging="True" 
            AllowSorting="True" 
            AutoGenerateColumns="False" 
            DataKeyNames="ID"
            >

            <Columns>
                <asp:BoundField 
                    DataField="ID" 
                    HeaderText="ID" 
                    SortExpression="ID" InsertVisible="False" ReadOnly="True" Visible="False" />

                <asp:BoundField 
                    DataField="FatherName" 
                    HeaderText="FatherName" 
                    SortExpression="FatherName" />

                <asp:BoundField DataField="MotherName" HeaderText="MotherName" 
                    SortExpression="MotherName" />

                <asp:ButtonField 
                    ButtonType="Button" 
                    CommandName="Select" 
                    Text="Select Details" />

                <asp:TemplateField ShowHeader="False">

                    <ItemTemplate>
                        <asp:Button 
                            ID="ButtonNewPersonToReleaseChildren" 
                            runat="server" 
                            CausesValidation="false" 
                            Text="New Person To Release Children"
                            CommandArgument='<%# Eval("ID") %>'
                            OnClick="NewPersonToReleaseChildren" />
                    </ItemTemplate>

                </asp:TemplateField>
            </Columns>
        </asp:GridView>

这是VB.Net代码隐藏编码,带有按钮的子例程:

Protected Sub GridViewParentsSummary_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GridViewParentsSummary.SelectedIndexChanged

    IntParentsID = GridViewParentsSummary.DataKeys(GridViewParentsSummary.SelectedIndex).Value

    Response.Redirect("AuthorizationForChildReleaseDetails.aspx")
End Sub

Protected Sub NewPersonToReleaseChildren(sender As Object, e As EventArgs)

    blnAddModeIsSelected = True

    MsgBox("The button was clicked.")

    Response.Redirect("AuthorizationForChildReleaseDetails.aspx")
End Sub

我确定我错过了一些编码,但不知道那可能是什么,因为Select按钮的子例程有效,但不是NewPersonToReleaseChildren的子例程。

2 个答案:

答案 0 :(得分:1)

在gridview中

<asp:TemplateField HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center"
                        FooterStyle-HorizontalAlign="Center">
                        <ItemTemplate>
                            <asp:ImageButton ID="ImgBtnDel" runat="server" ImageUrl="~/Images/icon-delete.gif" CommandName="del"
                                CommandArgument='<%# Eval("ID") %>' />
                        </ItemTemplate>
                    </asp:TemplateField>

在gridview中使用asp按钮或图像按钮,代码在后面:

Protected Sub gridview1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gridview1.RowCommand
    Dim myId As String = e.CommandArgument.ToString 
    If  e.CommandName = "del"  Then

    ElseIf e.CommandName = "upd" Then

    End If
End Sub

答案 1 :(得分:0)

Handles Handles NewPersonToReleaseChildren.Click添加到您的处理程序

Protected Sub NewPersonToReleaseChildren(sender As Object, e As EventArgs) Handles NewPersonToReleaseChildren.Click

    blnAddModeIsSelected = True

    //MsgBox("The button was clicked.")

    Response.Redirect("AuthorizationForChildReleaseDetails.aspx")
End Sub

我不认为asp.net中有MsgBox之类的内容。如果Handles不起作用,请将该行替换为Throw New Exception("My Button was called")或在该行上设置断点并按F5