Nested lists in Asp.net page
-
I am getting crazy with this problem. I am working on a page that is to display the milestones in a project. Each milestone contains a number of document templates that are to be listed under their correct milestone. This would create something like nested lists and I have absolutely no idea of how to do them. Right now I can only list the milestones. I do this with a repeater. Now I need a way to get into each row of this repeater and show the templates there. I have read articles on the net about nesting repeaters but they dont apply to the way I have constructed my code. They rely completely on a dataset and that you add relations in this dataset. I have one arraylist with objects that describe the milestones. For each milestone I get another arraylist containing the templates for that specific milestone. Please if you have any idea of how to show all this data please tell me. I am not required to use a repeater so any other idea will be helpful aswell. Thanks
-
I am getting crazy with this problem. I am working on a page that is to display the milestones in a project. Each milestone contains a number of document templates that are to be listed under their correct milestone. This would create something like nested lists and I have absolutely no idea of how to do them. Right now I can only list the milestones. I do this with a repeater. Now I need a way to get into each row of this repeater and show the templates there. I have read articles on the net about nesting repeaters but they dont apply to the way I have constructed my code. They rely completely on a dataset and that you add relations in this dataset. I have one arraylist with objects that describe the milestones. For each milestone I get another arraylist containing the templates for that specific milestone. Please if you have any idea of how to show all this data please tell me. I am not required to use a repeater so any other idea will be helpful aswell. Thanks
Hi there. You should be able to accomplish what you want by declaring within your main
Repeater
'sItemTemplate
the nested control (probably another Repeater in your case). Then code an event handler for the main Repeater's ItemDataBound[^] event. Here's an example using anArrayList
for the main data source; each object in the main ArrayList has its own ArrayList of nested objects used for the nested data source.<%@ Page Language="C#" %>
<script runat="server">void Page_Load(object o, EventArgs e)
{
if (!IsPostBack) BindMainData();
}ArrayList GetMainDataSource()
{
// return an arraylist of objects to represent the main datasource
ArrayList arr = new ArrayList();
MainObject m;m = new MainObject("First Main Object"); m.NestedObjects.Add(new NestedObject("main 1, first nested object") ); m.NestedObjects.Add(new NestedObject("main 1, second nested object") ); m.NestedObjects.Add(new NestedObject("main 1, third nested object") ); arr.Add(m); m = new MainObject("Second Main Object"); m.NestedObjects.Add(new NestedObject("main 2, first nested object") ); m.NestedObjects.Add(new NestedObject("main 2, second nested object") ); m.NestedObjects.Add(new NestedObject("main 2, third nested object") ); arr.Add(m); m = new MainObject("Third Main Object"); m.NestedObjects.Add(new NestedObject("main 3, first nested object") ); m.NestedObjects.Add(new NestedObject("main 3, second nested object") ); m.NestedObjects.Add(new NestedObject("main 3, third nested object") ); arr.Add(m); return arr;
}
void BindMainData()
{
// bind the main datasource
rptMain.DataSource = GetMainDataSource();
rptMain.DataBind();
}void rptMain_ItemDataBound(object o, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item
|| e.Item.ItemType == ListItemType.AlternatingItem)
{
// if this is a normal item type, then locate the nested repeater
Repeater rpt = e.Item.FindControl("rptNested") as Repeater;
i