Home > DeveloperSection > Forums > ItemCommand Event in Nested Repeater and listview
Anoop Singh
Anoop Singh

Total Post:12

Points:84
Posted on    October-16-2010 4:09 AM

 ASP.Net ASP.Net 
Ratings:


 1 Reply(s)
 8763  View(s)
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.


Alex R
Alex R

Total Post:40

Points:280
Posted on    October-18-2010 2:03 AM

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 Oct-18-2010 02:09:27 AM

Don't want to miss updates? Please click the below button!

Follow MindStick