1

Please help me to fire the command of ItemCommand for child Repeater.

Here is my aspx code.

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

And my aspx.vb code is

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

    End If
End Sub

But it's not firing.

I already added OnItemCommand on my child repeater but it gives me an error.

I also added AddHandler rptSO.ItemCommand, AddressOf rpSO_ItemCommand in the Parent Repeater but still no luck.

Thanks in advance for the help.

VDWWD
  • 35,079
  • 22
  • 62
  • 79
Dao Xio
  • 148
  • 11

2 Answers2

0

Just adding a CommandName to a button will not make things happen in code behind spontaneously. You need to add a OnCommand to the Button or an OnItemCommand to the Repeater.

<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
VDWWD
  • 35,079
  • 22
  • 62
  • 79
  • it gives me Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: BC30456: 'btn_Command' is not a member of 'ASP.viewdetails_aspx'. – Dao Xio Mar 29 '17 at 09:36
  • Did you recompile? And I used a translator to get the C# o VB. You can recreate the Subs by removing them and typing `OnCommand=` on the page, visual studio will ask you to create the method. – VDWWD Mar 29 '17 at 09:46
0

Solution:

Put the AddHandler in the Repeater Item Created.

This link helps me to solve my problem.

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

Dao Xio
  • 148
  • 11
  • 2
    I'd be careful. _Links to external resources are encouraged, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline._ I would consider bringing in the relevant content into your answer. As it stands you may be downvoted. – Bugs Mar 29 '17 at 11:19