?
Solved

How do I bind nested repeaters to lists in lists in code? see example

Posted on 2005-03-14
4
Medium Priority
?
422 Views
Last Modified: 2008-03-10
Hey

I create an arraylist with a list of objects. and binds it to a repeater like this:

for (int j=0; j<_esubjectmenuitem_eitemdescriptionlist.Count;j++)
 {
          ESubjectMenuItem_EItemDescription _esmi_eid1 =  
                                 (ESubjectMenuItem_EItemDescription)_esubjectmenuitem_eitemdescriptionlist[j];
          EItemDescription _eid = (EItemDescription)_esmi_eid1.EItemDescription;    
          _eitemdescriptionlist.Add(_eid);    
}

rptEItemDescription.DataSource = _eitemdescriptionlist;
rptEItemDescription.DataBind();

It works ok.
In my _eid - objects I have an ArrayList as a property: _eitemdescriptionsublist;
I want to bind it in the code to a nested repeater inside every instance of _eid so I can iterate through both the primary list and the nested list.
How can I do that?



0
Comment
Question by:JorgenVester
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
b1xml2 earned 1000 total points
ID: 13554792
rptEItemDescription.ItemDataBound += new RepeaterItemEventHandler(rptEItemDescription_ItemDataBound);
rptEItemDescription.DataSource = _eitemdescriptionlist;
rptEItemDescription.DataBind();



private void rptEItemDescription_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
   if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
   {
            Repeater repeater = e.Item.FindControl("rptEItemDescriptionSubList") as Repeater;
            EItemDescription data = e.Item.DataItem as EItemDescription;
            if (repeater != null && data != null)
            {
                  repeater.DataSource = data;
                  repeater.DataBind();
            }

  }
}

Assumptions:
1. We are assuming the nested repeater is called rptEItemDescriptionSubList.
2. You are going to have to change the structure of your classes...but the snippet above will have you understand that in order to use nested repeaters, you have to hook into the ItemDataBound event and at runtime and upon binding, find the nested repeater and bind to it.
0
 

Author Comment

by:JorgenVester
ID: 13556102
Just what I needed.
Thank you.

I made two changes and then it worked:

1. I hooked up the event like this in InitializeComponent() -  // maybe just a matter if taste.
this.rptEItemDescription.ItemDataBound += new RepeaterItemEventHandler(rptEItemDescription_ItemDataBound);

2. I did not have to change my classes. Only mad one small addition to get to the sublevel.
I have put a comment in the code to show where.

private void rptEItemDescription_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
   if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
   {
          Repeater repeater = e.Item.FindControl("rptEItemDescriptionSubList") as Repeater;
          EItemDescription data = e.Item.DataItem as EItemDescription;
          if (repeater != null && data != null)
          {
               repeater.DataSource = data.rptEItemDescriptionSubList; //this change was made to get to the sublevellist
               repeater.DataBind();
          }

  }
}

Just a matter of details. You solved the problem for me.


0
 

Author Comment

by:JorgenVester
ID: 13556128
I made a mistake in the code when I wrote it here. Here is the correct version:

private void rptEItemDescription_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
   if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
   {
          Repeater repeater = e.Item.FindControl("rptEItemDescriptionSubList") as Repeater;
          EItemDescription data = e.Item.DataItem as EItemDescription;
          if (repeater != null && data != null)
          {
               repeater.DataSource = data.EItemDescriptionSubList; //this change was made to get to the sublevellist - v. 2
               repeater.DataBind();
          }

  }
}

0
 
LVL 23

Expert Comment

by:b1xml2
ID: 13562144
I am glad to have helped =)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question