Nested Repeater Event Handling

Discussion in 'ASP .Net Web Controls' started by KeithRaginF@newsgroups.nospam, Apr 20, 2004.

  1. Guest

    (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


    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!
    , Apr 20, 2004
    1. Advertisements

  2. 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;

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

    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! -
    This posting is provided "as is" with no warranties and confers no rights.
    Jeffrey Tan[MSFT], Apr 20, 2004
    1. Advertisements

  3. KeithRaginF Guest

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

    I appreciate it.
    KeithRaginF, Apr 20, 2004
  4. 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! -
    This posting is provided "as is" with no warranties and confers no rights.
    Jeffrey Tan[MSFT], Apr 21, 2004
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ravi
    Aug 18, 2006
  2. Patrik Persson
    Patrik Persson
    Aug 30, 2004
  3. Mauritsius
    John Saunders
    Dec 17, 2004
  4. Replies:
  5. Replies:
  6. Replies:
    Karl Seguin
    Aug 10, 2005
  7. uncensored
    Oct 25, 2006
  8. Per Salmi

    Repeater with Checkboxes, handling CheckedChanged event?

    Per Salmi, Feb 24, 2004, in forum: ASP .Net Web Controls
    Jeffrey Tan[MSFT]
    Feb 26, 2004