ItemCommand Event in Nested Repeater and listview

Total Post:12

Points:84

 12494  View(s)
Ratings:
Rate this:
Hello,

I'mworking on a project where I've to use ListView inside a nested repeater. I'm able to bind controls of listview and repeater at runtime but I'm unable to handle the ItemCommand event of ListView inside repeater.

My .aspx file looks like this

<
asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
<ItemTemplate>
<table">
<tr>
<td> <asp:Label ID="Label1" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Repeater ID="Repeater2" runat="server">
<ItemTemplate>
<table style="width: 100%;">
<tr style="width: 100%; background-color: Silver; color: Maroon;">
<td> <asp:Label ID="Label2" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:ListView ID="ListView1" runat="server">
<ItemTemplate>
<tr style="width: 100%;">
<td style="width: 70%;">
<asp:Label ID="Label3" runat="server"></asp:Label>
</td> <td style="width: 10%; text-align: center;">
<asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton>
</td>
<td style="width: 10%; text-align: center;">
<asp:LinkButton ID="LinkButton2" runat="server">LinkButton2</asp:LinkButton>
</td>
</tr> </ItemTemplate>
<LayoutTemplate>
<table id="Table1" runat="server" style="width: 100%;">
<tr id="itemPlaceholder" runat="server" style="width: 100%;">
</tr>
</table>
</LayoutTemplate>
</asp:ListView> </td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater> </td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>

On click of LinkButton1 and LinkButton2 I want to write some code, but I'm unable to handle the click event of LinkButton inside ListView which is inside two nested Repeater.

Please help me solving the problem.

Thanks in advance.
  1. Re: ItemCommand Event in Nested Repeater and listview

    Hi Anoop,

    You have to write Code in ItemCreated Event of Repeater.

     

        protected void Repeater1_ItemCreated(object sender, RepeaterItemEventArgs e)
        {
            Repeater Repeater2 = e.Item.FindControl("Repeater2") as Repeater;
            Repeater2.ItemCreated+=new RepeaterItemEventHandler(Repeater2_ItemCreated);
        }
     
        protected void Repeater2_ItemCreated(object sender, RepeaterItemEventArgs e)     {         ListView ListView1 = e.Item.FindControl("ListView1") as ListView;         ListView1.ItemCommand+=new EventHandler<ListViewCommandEventArgs>(ListView1_ItemCommand);     }

    This will solve your problem.

      Modified On Mar-29-2018 02:15:09 AM

Answer

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.