Nested Repeater
-
Hey Guys, I am having a hard time with nesting a repeater. Here is what I'm trying to do: I have a Parent Repeater named Repeater1 then inside that repeater I have a nested repeater named ChildRepeater and I'm needing to place another Repeater within the ChildRepeater named SubChildRepeater but here is my question. How would you be able to access the SubChildRepeater in order to bind the corresponding data to that repeater. I'm really not too sure how this would happen I have created one Application that uses the repeater and it hides the child information then on selection of the repeater item it displays the child data and the child data contains a nested repeater that has the subchild information but there is a limitation of one record for the Child data and there can of course be many records in the sub-child data thanks to the repeater. If anyone has any ideas or angles to try doing this i would appreciate it. I have tried just about all of the tricks up my sleeves with no luck, so you're ideas and/or help would be greatly appreciated.
You would probably want a main repeater and in the Item created event create a dynamic repeater. And just recursively create another one. It sounds like you should create your web control. And produce your own table through the render method. After all, thats what the repeater does. You could place the repeater inside an ascx web user control and that might be somewhat organized. The reptear could place multiple Web User Controls. The problem is debugging that will be an absolute nightmare. So whichever way you do it, make sure its clear what your doing. I would make a Web Server Control, but thats me. Whats going on would be the clearest that way. Nick 1 line of code equals many bugs. So don't write any!!
-
You would probably want a main repeater and in the Item created event create a dynamic repeater. And just recursively create another one. It sounds like you should create your web control. And produce your own table through the render method. After all, thats what the repeater does. You could place the repeater inside an ascx web user control and that might be somewhat organized. The reptear could place multiple Web User Controls. The problem is debugging that will be an absolute nightmare. So whichever way you do it, make sure its clear what your doing. I would make a Web Server Control, but thats me. Whats going on would be the clearest that way. Nick 1 line of code equals many bugs. So don't write any!!
Thanks for yall's ideas here is the big question I think. I have been able to do everything for the first two repeaters, but I'm having an issue accessing the third repeater. I need to access the third repeater so that I can bind data to that repeater. Once I can access the repeater, I will be able to access the properties of the repeater and do with it what I want to. Does anyone know a way to access a repeater nested within another nested repeater? Sorry I probably could have asked it this simply before. Thanks for any help you guys.
-
Thanks for yall's ideas here is the big question I think. I have been able to do everything for the first two repeaters, but I'm having an issue accessing the third repeater. I need to access the third repeater so that I can bind data to that repeater. Once I can access the repeater, I will be able to access the properties of the repeater and do with it what I want to. Does anyone know a way to access a repeater nested within another nested repeater? Sorry I probably could have asked it this simply before. Thanks for any help you guys.
When you raise an itemcommand event on your 1st nested repeater, you should be able to find your 2nd nested repeater at that moment... If your itemcommand event isn't being raised for your 1st repeater, chances are, it isn't being databound on the postback. I don't want to say anything more unless you first try to see if you can raise the itemcommand event on the 1st nested repeater because maybe I'm being too confusing. First try to debug and see if you can raise an itemcommand event for the 1st nested repeater. If this is the case then you should be able to find your 2nd repeater in that same item of the repeater. I guess you know how to, but just as reminder, Inside the ItemCommand event: //e is the event's arguments for the ItemCommand Event If(e.CommandName = "BindSecondRepeater"){ Repeater SecondNestedRepeater = (Repeater)e.Item.FindControl("SecondNestedRepeater"); // Your code to retrieve the necessary info from database here SecondNestedRepeater.DataSource = InfoToBind; SecondNestedRepeater.DataBind(); } :wtf: I better take it easy :P. daniero
-
When you raise an itemcommand event on your 1st nested repeater, you should be able to find your 2nd nested repeater at that moment... If your itemcommand event isn't being raised for your 1st repeater, chances are, it isn't being databound on the postback. I don't want to say anything more unless you first try to see if you can raise the itemcommand event on the 1st nested repeater because maybe I'm being too confusing. First try to debug and see if you can raise an itemcommand event for the 1st nested repeater. If this is the case then you should be able to find your 2nd repeater in that same item of the repeater. I guess you know how to, but just as reminder, Inside the ItemCommand event: //e is the event's arguments for the ItemCommand Event If(e.CommandName = "BindSecondRepeater"){ Repeater SecondNestedRepeater = (Repeater)e.Item.FindControl("SecondNestedRepeater"); // Your code to retrieve the necessary info from database here SecondNestedRepeater.DataSource = InfoToBind; SecondNestedRepeater.DataBind(); } :wtf: I better take it easy :P. daniero
Thanks for your idea, I have already bound to the first 2 repeaters and it's the third repeater that I can't figure out how to access. I am confused about how you would go about accessing the third repeater since you access the second repeater in the ItemBound event of the first one. I figured there would be some way of performing the same type of thing except this time for the third repeater being accessed on item bound of the second one. but I can't seem to raise the itembound event of the second repeater. If I could figure out a way to access the third repeater in the itembound of the second repeater then I would be able to do everything I want to accomplish. Thanks for all your help.
-
Thanks for your idea, I have already bound to the first 2 repeaters and it's the third repeater that I can't figure out how to access. I am confused about how you would go about accessing the third repeater since you access the second repeater in the ItemBound event of the first one. I figured there would be some way of performing the same type of thing except this time for the third repeater being accessed on item bound of the second one. but I can't seem to raise the itembound event of the second repeater. If I could figure out a way to access the third repeater in the itembound of the second repeater then I would be able to do everything I want to accomplish. Thanks for all your help.
What I think it's possibly happening is that your 1st nested repeater is empty on postback. So on page_load, you'd need to bind that 2nd repeater, somehow identify when you should bind it and do so in page_load on the postback. What's possibly happens is that on postback, the 1st nested repeater is empty and the viewstate isn't loading, and therefore is not raising the itemcommand event so you could databind your 2nd nested repeater. Going crazy here :rolleyes: :wtf:. daniero
-
What I think it's possibly happening is that your 1st nested repeater is empty on postback. So on page_load, you'd need to bind that 2nd repeater, somehow identify when you should bind it and do so in page_load on the postback. What's possibly happens is that on postback, the 1st nested repeater is empty and the viewstate isn't loading, and therefore is not raising the itemcommand event so you could databind your 2nd nested repeater. Going crazy here :rolleyes: :wtf:. daniero
Ok I must have really been confusing you. I am able to bind the first 2 repeaters without any problems, but the problem I'm having is that when the second repeater is bound I need a way to access the itembound property of the second repeater. when you nest one repeater inside of another one, you can't access that control directly from the code behind which is why when you bind the first repeater you have to go into the itemBound event of the first repeater and use the command "e.item.findcontrol("nestedrepeater")" to get the nested repeater from the items collection. Now when you do that you then can bind data to that repeater but there is not an ItemBound property for the nested repeater in the codebehind, also all you can access from the codebehind is the main repeater. So, the problem I keep running in to is that since there is no ItemBound event for the second repeater, then I need a way to force the ItemBound event of the Second repeater, so I will be able to access the third repeater in the code behind and bind data to that repeater. So, I need to know of a way to force the ItemBound event of a nested control, so that I can use that event to bind the third repeater. Thanks for all of the help guys.
-
Ok I must have really been confusing you. I am able to bind the first 2 repeaters without any problems, but the problem I'm having is that when the second repeater is bound I need a way to access the itembound property of the second repeater. when you nest one repeater inside of another one, you can't access that control directly from the code behind which is why when you bind the first repeater you have to go into the itemBound event of the first repeater and use the command "e.item.findcontrol("nestedrepeater")" to get the nested repeater from the items collection. Now when you do that you then can bind data to that repeater but there is not an ItemBound property for the nested repeater in the codebehind, also all you can access from the codebehind is the main repeater. So, the problem I keep running in to is that since there is no ItemBound event for the second repeater, then I need a way to force the ItemBound event of the Second repeater, so I will be able to access the third repeater in the code behind and bind data to that repeater. So, I need to know of a way to force the ItemBound event of a nested control, so that I can use that event to bind the third repeater. Thanks for all of the help guys.
You need to add a delegate to the Itemdatabound event of the 2nd repeater before calling the databind method. In Visual Basic this should be something like this: AddHandler YourRepeater.ItemDataBound, AddressOf method and method should be something like: Private Sub method(ByVal o As Object, ByVal e As RepeaterItemEventArgs) 'Your code to handle the event End Sub In C#, this would be something like: YourRepeater.ItemDataBound += new RepeaterItemEventHandler(method); and method should be something like: private void method(object o, RepeaterItemEventArgs e) { //your code to handle the event } daniero
-
You need to add a delegate to the Itemdatabound event of the 2nd repeater before calling the databind method. In Visual Basic this should be something like this: AddHandler YourRepeater.ItemDataBound, AddressOf method and method should be something like: Private Sub method(ByVal o As Object, ByVal e As RepeaterItemEventArgs) 'Your code to handle the event End Sub In C#, this would be something like: YourRepeater.ItemDataBound += new RepeaterItemEventHandler(method); and method should be something like: private void method(object o, RepeaterItemEventArgs e) { //your code to handle the event } daniero
In case you'd like to have some examples, minhpc_bk made a suggestion to someone also asking for [help on nested repeaters to look around](http://www.google.com/search?hl=vi&q=ASP.NET+nested+repeater&meta= rel=)[^] minhpc_bk rocks you know? he always has good answers :)
-
Ok I must have really been confusing you. I am able to bind the first 2 repeaters without any problems, but the problem I'm having is that when the second repeater is bound I need a way to access the itembound property of the second repeater. when you nest one repeater inside of another one, you can't access that control directly from the code behind which is why when you bind the first repeater you have to go into the itemBound event of the first repeater and use the command "e.item.findcontrol("nestedrepeater")" to get the nested repeater from the items collection. Now when you do that you then can bind data to that repeater but there is not an ItemBound property for the nested repeater in the codebehind, also all you can access from the codebehind is the main repeater. So, the problem I keep running in to is that since there is no ItemBound event for the second repeater, then I need a way to force the ItemBound event of the Second repeater, so I will be able to access the third repeater in the code behind and bind data to that repeater. So, I need to know of a way to force the ItemBound event of a nested control, so that I can use that event to bind the third repeater. Thanks for all of the help guys.
Hi there, I believe that when you can bind data to the nested repeaters, then you can also apply the same pattern to the three repeaters. Below is a quick example that demonstrates what you might want to do:
<%@ Page language="c#" %>
<html>
<head>
<title>The Nested Repeaters Example</title>
<script language="C#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
BindParentRepeater();
}private void BindParentRepeater() { ArrayList list = new ArrayList(); list.Add("ParentItem1"); list.Add("ParentItem2"); list.Add("ParentItem3"); parentRepeater.DataSource = list; parentRepeater.DataBind(); } private void BindChildRepeater(string parentItem, Repeater childRepeater) { ArrayList list = new ArrayList(); list.Add(parentItem + "\_ChildItem1"); childRepeater.DataSource = list; childRepeater.DataBind(); } private void BindSubChildRepeater(string childItem, Repeater subChildRepeater) { ArrayList list = new ArrayList(); list.Add(childItem + "\_SubChildItem1"); list.Add(childItem + "\_SubChildItem2"); list.Add(childItem + "\_SubChildItem3"); subChildRepeater.DataSource = list; subChildRepeater.DataBind(); } protected void parentRepeater\_ItemDataBound(object sender, RepeaterItemEventArgs e) { if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { string dataItem = e.Item.DataItem as string; Repeater childRepeater = e.Item.FindControl("childRepeater")as Repeater; BindChildRepeater(dataItem, childRepeater); } } protected void childRepeater\_ItemDataBound(object sender, RepeaterItemEventArgs e) { if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { string dataItem = e.Item.DataItem as string; Repeater subChildRepeater = e.Item.FindControl("subChildRepeater")as Repeater; BindSubChildRepeater(dataItem, subChildRepeater); } } </script> </head> <body MS\_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <asp:Repeater OnItemDataBound="parentRepeater\_ItemDataBoun
-
Hi there, I believe that when you can bind data to the nested repeaters, then you can also apply the same pattern to the three repeaters. Below is a quick example that demonstrates what you might want to do:
<%@ Page language="c#" %>
<html>
<head>
<title>The Nested Repeaters Example</title>
<script language="C#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
BindParentRepeater();
}private void BindParentRepeater() { ArrayList list = new ArrayList(); list.Add("ParentItem1"); list.Add("ParentItem2"); list.Add("ParentItem3"); parentRepeater.DataSource = list; parentRepeater.DataBind(); } private void BindChildRepeater(string parentItem, Repeater childRepeater) { ArrayList list = new ArrayList(); list.Add(parentItem + "\_ChildItem1"); childRepeater.DataSource = list; childRepeater.DataBind(); } private void BindSubChildRepeater(string childItem, Repeater subChildRepeater) { ArrayList list = new ArrayList(); list.Add(childItem + "\_SubChildItem1"); list.Add(childItem + "\_SubChildItem2"); list.Add(childItem + "\_SubChildItem3"); subChildRepeater.DataSource = list; subChildRepeater.DataBind(); } protected void parentRepeater\_ItemDataBound(object sender, RepeaterItemEventArgs e) { if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { string dataItem = e.Item.DataItem as string; Repeater childRepeater = e.Item.FindControl("childRepeater")as Repeater; BindChildRepeater(dataItem, childRepeater); } } protected void childRepeater\_ItemDataBound(object sender, RepeaterItemEventArgs e) { if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { string dataItem = e.Item.DataItem as string; Repeater subChildRepeater = e.Item.FindControl("subChildRepeater")as Repeater; BindSubChildRepeater(dataItem, subChildRepeater); } } </script> </head> <body MS\_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <asp:Repeater OnItemDataBound="parentRepeater\_ItemDataBoun
Thank you very much for your information. The problem was that I couldn't access the control from the code behind whic is what I was trying to do. After seeing your example I moved the code to the script portion of the page and it works great. Thanks
-
Thank you very much for your information. The problem was that I couldn't access the control from the code behind whic is what I was trying to do. After seeing your example I moved the code to the script portion of the page and it works great. Thanks
That's great to hear :) I told you, min always has good advice. daniero