Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5954977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:02:54+00:00 2026-05-22T18:02:54+00:00

I need to know how to nest repeaters within a user control. The html

  • 0

I need to know how to nest repeaters within a user control. The html side of things is fine, it’s the binding and code behind I need help with. I’ve only been able to find examples using an sql data source, which doesn’t really help.

My repeaters look like this:

<asp:Panel ID="pnlDiscipline" runat="server" CssClass="">
    <asp:Repeater ID="rptDiscipline" runat="server">
        <ItemTemplate>
            <h4><%#Eval("Discipline")%></h4>
            <ul>
                <asp:Repeater ID="rptPrograms" runat="server">
                    <ItemTemplate>
                        <li><asp:HyperLink runat="server" Text='<%#Eval("Name") %>' NavigateUrl='<%#Eval("Link") %>'></asp:HyperLink> <%#Eval ("Notation") %></li>
                    </ItemTemplate>
                </asp:Repeater>
            </ul>
        </ItemTemplate>
    </asp:Repeater>

What I need to do is hopefully reasonably clear – the h4 discipline should appear once, all the entries that belong to the discipline are listed below, then the next h4, then the appropriate list, the next h4 and so on.

The datasource is a dataview created in the codebehind where each row has ‘Name’, “Link’, ‘NOtation’ and ‘Discipline’. I’ve bound the dataview to the outermost repeater, and it behaves as expected – lists the discipline name for each entry, but shows no data in the inner repeater.

How do I go about making this work?

EDIT: Just to clarify, I have one datatable in the codebehind. Each row in that table is an item, each item belongs to a discipline. I want to use the outer repeater to list the disciplines, the inner to list the items grouped under each discipline. Like so:

<h4>DISCIPLINE 1</h4>
    <ul>
        <li>Item</li>
        <li>Item</li>
        <li>Item</li>
    </ul>
<h4>DISCIPLINE 2</h4>
    <ul>        
        <li>Item</li>            
        <li>Item</li>
    </ul>
<h4>DISCIPLINE 3</h4>
    <ul>        
        <li>Item</li>            
        <li>Item</li>
    </ul>

At present, binding the datatable to the outer repeater gives this (example uses the data above):

    <h4>DISCIPLINE 1</h4>
    <h4>DISCIPLINE 1</h4>
    <h4>DISCIPLINE 1</h4>
    <h4>DISCIPLINE 2</h4>
    <h4>DISCIPLINE 2</h4>
    <h4>DISCIPLINE 3</h4>
    <h4>DISCIPLINE 3</h4>

I’ve used OnItemDataBound on the outer repeater as suggested, and as a test case am able to access the data:

protected void rptDiscipline_ItemDataBound(Object Sender, RepeaterItemEventArgs e) 
{
    DataRowView drView = (DataRowView) e.Item.DataItem;
    string name = drView["Name"] as string;
    string link = drView["Link"] as string;
    string notation = drView["Notation"] as string;
    Response.Write(name + link + notation + "<br />")
}

So the data is there, it is exactly what I would expect to see, I just can’t get it bound to the inner repeater. If there is a more performant way to achieve the same, I’m happy to rework my solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:02:54+00:00Added an answer on May 22, 2026 at 6:02 pm

    On the outer control, use the ItemDataBound event, like this:

    <asp:Repeater ID="rptDiscipline" runat="server"
         OnItemDataBound="rptDiscipline_ItemDataBound">
    ...
    

    Then, in the code-behind, handle the rptDiscipline_ItemDataBound event and manually bind the inner repeater. The repeater’s ItemDataBound event fires once for each item that is repeated. So you’ll do something like this:

    protected void rptDiscipline_ItemDataBound(Object Sender, RepeaterItemEventArgs e) 
    {
        // To get your data item, cast e.Item.DataItem to 
        // whatever you're using for the data object; for example a DataRow.
    
        // Get the inner repeater:
        Repeater rptPrograms = (Repeater) e.Item.FindControl("rptPrograms");
    
        // Set the inner repeater's datasource to whatever it needs to be.
        rptPrograms.DataSource = ...
        rptPrograms.DataMember = ...
        rptPrograms.DataBind();
    }
    

    EDIT: Updated to match your question’s update.

    You need to bind the outer repeater to a data source that has only one record per item you want the repeater to render. That means the data source needs to be a collection/list/datatable/etc that has only the disciplines in it. In your case, I would recommend getting a List<string> of disciplines from the DataTable for the inner collection, and bind the outer repeater to that. Then, the inner repeater binds to a subset of the data in the DataTable, using the ItemDataBound event. To get the subset, filter the DataTable through a DataView.

    Here’s code:

    protected void Page_Load(object sender, EventItems e)
    {
        // get your data table
        DataTable table = ...
    
        if ( !IsPostBack )
        {
            // get a distinct list of disciplines
            List<string> disciplines = new List<string>();
            foreach ( DataRow row in table )
            {
                string discipline = (string) row["Discipline"];
                if ( !disciplines.Contains( discipline ) )
                    disciplines.Add( discipline );
            }
            disciplines.Sort();
    
            // Bind the outer repeater
            rptDiscipline.DataSource = disciplines;
            rptDiscipline.DataBind();
        }
    }
    
    protected void rptDiscipline_ItemDataBound(Object Sender, RepeaterItemEventArgs e) 
    {
        // To get your data item, cast e.Item.DataItem to 
        // whatever you're using for the data object
        string discipline = (string) e.Item.DataItem;
    
        // Get the inner repeater:
        Repeater rptPrograms = (Repeater) e.Item.FindControl("rptPrograms");
    
        // Create a filtered view of the data that shows only 
        // the disciplines needed for this row
        // table is the datatable that was originally bound to the outer repeater
        DataView dv = new DataView( table );  
        dv.RowFilter = String.Format("Discipline = '{0}'", discipline);
    
        // Set the inner repeater's datasource to whatever it needs to be.
        rptPrograms.DataSource = dv;
        rptPrograms.DataBind();
    }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to know how to turn on Code Coverage when running TFS builds
I need to know, from within Powershell, if the current drive is a mapped
I need to know when the user finishes editing a cell in an NSTableView.
I have logged FBA user in Sharepoint 2010 with FBA and need know what
Hallo. I need know user name of user which run browser. If I use
Need to know this so that i could send DTMF and that is going
I need to know about Epoll On linux System. Could you recommend manual or
I need to know how the performance of different XML tools (parsers, validators, XPath
I need to know how much space occupies all the databases inside an SQL
I need to know when the memory will be allocated for a particular program.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.