ItemCommand Event in Nested Repeater and listview

Total Post:12

 12354  View(s)
Rate this:

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">
<td> <asp:Label ID="Label1" runat="server"></asp:Label>
<asp:Repeater ID="Repeater2" runat="server">
<table style="width: 100%;">
<tr style="width: 100%; background-color: Silver; color: Maroon;">
<td> <asp:Label ID="Label2" runat="server"></asp:Label>
<asp:ListView ID="ListView1" runat="server">
<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 style="width: 10%; text-align: center;">
<asp:LinkButton ID="LinkButton2" runat="server">LinkButton2</asp:LinkButton>
</tr> </ItemTemplate>
<table id="Table1" runat="server" style="width: 100%;">
<tr id="itemPlaceholder" runat="server" style="width: 100%;">
</asp:ListView> </td>
</asp:Repeater> </td>

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. Post:40

    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


Please check, If you want to make this post sponsored

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