0

We have a GridView with a 2 buttons. One of the buttons is a select button and the other is a one without a command. It is supposed to activate an OnClick sub routine. The sub routine is not executing.

Here is the markup of the GridView with the buttons:

        <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>

Here is the VB.Net code-behind coding with the sub routines for the buttons:

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

I'm sure I am missing some coding but don't know what that could be because the sub routine for the Select button works, but not the sub routine for NewPersonToReleaseChildren.

4

2 回答 2

1

在网格视图中:

<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 中使用 aspButton 或 Imagebutton,在后面的代码中:

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
于 2012-09-30T07:49:15.870 回答
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

我认为MsgBox在 asp.net 中没有类似的东西。如果Handles不起作用,请将该行替换为该行Throw New Exception("My Button was called")或在该行上放置一个断点,然后按 F5

于 2012-09-30T07:58:29.140 回答