Nested Repeater Event Handling

K

KeithRaginF

(I apologize for repeatedly posting this --- I am having a little trouble getting my MSDN Universal Managed Newsgroup ID set-up. Hopefully, this one will result in a response.

I have 1 repeater nested inside another. It looks something like this

<asp:Repeater id="RepeaterOuter" runat="server" DataSource="<%# GetStuffToIterateOver() %"><ItemTemplate><various controls><asp:Repeater id="RepeaterInner" runat="server"
DataSource="<%# Container.DataItem.GetAnArrayOfStrings() %>"><ItemTemplate><asp:LinkButton CommandName='<%# Container.DataItem %>' ID="Linkbutton1" Runat="server"><%# Container.DataItem] %></asp:LinkButton>&nbsp &nbs

</ItemTemplate></asp:Repeater></ItemTemplate></asp:Repeater

The outer repeater displays groups of data. Each group contains a series of linkbuttons which are also created by a repeater (the inner repeater). What I can't figure out is how to determine which linkbutton has been clicked. By setting the commandname of the linkbutton, I know which item in the inner repeater caused the event. But, I can't determine from which item in the outer repeater the event came from

I bound the following to the ItemCreated event of the outer repeater to capture events from the inner repeater

private void RepeaterOuter_ItemCreated(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e

Repeater links = e.Item.FindControl("RepeaterInner") as Repeater
links .ItemCommand += new RepeaterCommandEventHandler(this.RepeaterInner_ItemCommand)


Inside RepeaterInner_ItemCommand, I can succesfully interogate e.CommandName to find out which linkbutton was pressed. How do I determine which item in the outer repeater, though

One approach where I hit a dead-end was to embed additional information in the linkbutton tag to identify the outer repeater item. For instance, setting the CommandArgument with something that will identify the item of the outer repeater, except, I don't know how to access it. Is there a way to get at the Container.DataItem of the parent repeater from inside the nested repeater? Or is there a better approach to this

Thanks for any assistance!
 
J

Jeffrey Tan[MSFT]

Hi KeithRaginF,

Thanks for your posting!

Based on my understanding, you nested some repeater control in a main
repeater control. Also, there are some linkbuttons in that inner repeater
control. You have succeeded handle the Inner repeater control's ItemCommand
event, but you want to find a way to determine which inner repeater
control, this event came from.

In the inner repeater control's ItemCommand event, you can use
RepeaterCommandEventArgs.Item.NamingContainer to get the inner repeater
control's reference.

Then you may just loop through the each inner repeater of the outter
repeater control to do the reference comparison, then you can determine the
inner repeater control in which row fires the event.

Also, if you just want to determine row number of the inner repeater
control in the outter repeater, you can just do like this:

private void RepeaterInner_ItemCommand(object source,
System.Web.UI.WebControls.RepeaterCommandEventArgs e)
{
Repeater r=(Repeater)e.Item.NamingContainer;
RepeaterItem ri=r.NamingContainer;
this.Response.Write(ri.ItemIndex.ToString());
}

=====================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
K

KeithRaginF

Excellent. Thank you, Jeffrey. The technique of interrogating the outer repeater through the NamingContainers solved my problem

I appreciate it.
 
J

Jeffrey Tan[MSFT]

Hi KeithRaginF,

Thanks very much for your feedback.

I am glad I can help you. You are welcome!!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top