嵌套中继器内的按钮

Button inside Nested Repeater

请帮我触发子 Repeater 的 ItemCommand 命令。

这是我的 aspx 代码。

<asp:Repeater ID="rpCompany" runat="server">
    <HeaderTemplate>
        <div id="accordion" class="details-accordion">
    </HeaderTemplate>
    <ItemTemplate>
        <h3 class="details-header clr">
            Company Name
        </h3>
        <div class="col-sm-12 details-content">
            <asp:Repeater ID="rpSO" runat="server">
                <HeaderTemplate>
                    <div id="SO">
                        <div id="accordion2" class="details-accordion">
                </HeaderTemplate>
                <ItemTemplate>
                    <h3 class="details-header clr">
                        SO Number
                    </h3>
                    <div class="col-xs-12 details-content">
                        <div class="col-xs-12 btn-center">
                            <asp:Button ID="btnSave" runat="server" Text="SAVE" CssClass="btn btn-primary btn-blue-save" CommandName="SAVE" />
                        </div>
                        <div class="clr"></div>
                        <div class="col-xs-12">
                            <asp:Label ID="lblErrorSave" runat="server" Text=""></asp:Label>
                        </div>
                    </div>
                </ItemTemplate>
                <FooterTemplate>
                    </div>
                </div>
                </FooterTemplate>
            </asp:Repeater>
        </div>
    </ItemTemplate>
    <FooterTemplate>
        </div>
    </FooterTemplate>
</asp:Repeater>

我的 aspx.vb 密码是

Private Sub rpSO_ItemCommand(sender As Object, e As RepeaterCommandEventArgs)
    If e.CommandName = "SAVE" Then

    End If
End Sub

但它没有开火。

我已经在我的子转发器上添加了 OnItemCommand,但它给我一个错误。

我还在 Parent Repeater 中添加了 AddHandler rptSO.ItemCommand, AddressOf rpSO_ItemCommand,但仍然没有成功。

在此先感谢您的帮助。

仅向按钮添加 CommandName 不会使代码隐藏中的事情自发发生。您需要向 Button 添加 OnCommand 或向 Repeater 添加 OnItemCommand

<asp:Button ID="btnSave" runat="server" OnCommand="btnSave_Command" Text="SAVE" CommandName="SAVE" />

Protected Sub btnSave_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
    //code
End Sub

<asp:Repeater ID="rpSO" runat="server" OnItemCommand="rpSO_ItemCommand">

Protected Sub rpSO_ItemCommand(ByVal source As Object, ByVal e As RepeaterCommandEventArgs)
    //code
End Sub

解决方案:

AddHandler 放入创建的转发器项目中。

这个link帮助我解决了我的问题。

https://www.mindstick.com/Forum/45/itemcommand-event-in-nested-repeater-and-listview