nested repeater
-
Hi, I have question regarding using nested repeater. Can we use nested repeater in ascx file in asp.net ? Well I tried to use but the name of the child repeater is not recognizing. Can anybody has any idea on that ? thanks
suchita
-
Sure. Thanks for the reply. Well these are the codes.
<asp:Repeater runat="server" id="Repeater1">
<HeaderTemplate>items<br /><br /></HeaderTemplate>
<ItemTemplate>
<b><%# DataBinder.Eval(Container.DataItem, "catagoryname") %></t>
<br><%# DataBinder.Eval(Container.DataItem, "catagorydescription") %><asp:Repeater ID="Repeater3" runat="server"> <ItemTemplate> <br>Items: <%# DataBinder.Eval(Container.DataItem,"ItemName")%></t></t></t><%# DataBinder.Eval(Container.DataItem, "Amount") %> <br><%# DataBinder.Eval(Container.DataItem, "ItemDescription") %></br> </ItemTemplate> </asp:Repeater> </ItemTemplate> <separatortemplate> <br /> <br /> <br /> </separatortemplate> </asp:Repeater>
I have these in my ascx page.
suchita
-
Sure. Thanks for the reply. Well these are the codes.
<asp:Repeater runat="server" id="Repeater1">
<HeaderTemplate>items<br /><br /></HeaderTemplate>
<ItemTemplate>
<b><%# DataBinder.Eval(Container.DataItem, "catagoryname") %></t>
<br><%# DataBinder.Eval(Container.DataItem, "catagorydescription") %><asp:Repeater ID="Repeater3" runat="server"> <ItemTemplate> <br>Items: <%# DataBinder.Eval(Container.DataItem,"ItemName")%></t></t></t><%# DataBinder.Eval(Container.DataItem, "Amount") %> <br><%# DataBinder.Eval(Container.DataItem, "ItemDescription") %></br> </ItemTemplate> </asp:Repeater> </ItemTemplate> <separatortemplate> <br /> <br /> <br /> </separatortemplate> </asp:Repeater>
I have these in my ascx page.
suchita
You won't be able to access the Repeater3 control from the ascx directly as a new one is created for each databound item. If you handle the OnItemDataBound event on Repeater1 you'll be able to access the Repeater3 control using: e.Item.FindControl("Repeater3")
Freestyle Interactive Ltd Martin on .Net Follow Me on Twitter
-
Sure. Thanks for the reply. Well these are the codes.
<asp:Repeater runat="server" id="Repeater1">
<HeaderTemplate>items<br /><br /></HeaderTemplate>
<ItemTemplate>
<b><%# DataBinder.Eval(Container.DataItem, "catagoryname") %></t>
<br><%# DataBinder.Eval(Container.DataItem, "catagorydescription") %><asp:Repeater ID="Repeater3" runat="server"> <ItemTemplate> <br>Items: <%# DataBinder.Eval(Container.DataItem,"ItemName")%></t></t></t><%# DataBinder.Eval(Container.DataItem, "Amount") %> <br><%# DataBinder.Eval(Container.DataItem, "ItemDescription") %></br> </ItemTemplate> </asp:Repeater> </ItemTemplate> <separatortemplate> <br /> <br /> <br /> </separatortemplate> </asp:Repeater>
I have these in my ascx page.
suchita
You have not bound the nested Repeater so of course it will not display anything.
<asp:Repeater ID="Repeater3" runat="server" DataSource='<%# ((SiteMapNode)Container.DataItem).ChildNodes %>'>
I know the language. I've read a book. - _Madmatt
-
You won't be able to access the Repeater3 control from the ascx directly as a new one is created for each databound item. If you handle the OnItemDataBound event on Repeater1 you'll be able to access the Repeater3 control using: e.Item.FindControl("Repeater3")
Freestyle Interactive Ltd Martin on .Net Follow Me on Twitter
Martin Jarvis wrote:
You won't be able to access the Repeater3 control from the ascx directly
Why not? See below.
I know the language. I've read a book. - _Madmatt
-
You won't be able to access the Repeater3 control from the ascx directly as a new one is created for each databound item. If you handle the OnItemDataBound event on Repeater1 you'll be able to access the Repeater3 control using: e.Item.FindControl("Repeater3")
Freestyle Interactive Ltd Martin on .Net Follow Me on Twitter
-
You have not bound the nested Repeater so of course it will not display anything.
<asp:Repeater ID="Repeater3" runat="server" DataSource='<%# ((SiteMapNode)Container.DataItem).ChildNodes %>'>
I know the language. I've read a book. - _Madmatt
-
Thank you for the reply but adding that line still couldn't recognize the Repeater3 .. :(
suchita
SayamiSuchi wrote:
couldn't recognize the Repeater3
Please clarify what you mean by this. The example was for a nested Sitemap, you will of course need to adjust it to your usage.
I know the language. I've read a book. - _Madmatt
-
SayamiSuchi wrote:
couldn't recognize the Repeater3
Please clarify what you mean by this. The example was for a nested Sitemap, you will of course need to adjust it to your usage.
I know the language. I've read a book. - _Madmatt
I am taking datasource from the dataset which i passed it to the repeater1.I also tried like this:
<asp:Repeater runat="server" id="Repeater1">
<HeaderTemplate>items<br /><br /></HeaderTemplate>
<ItemTemplate>
<b><%# DataBinder.Eval(Container.DataItem, "catagoryname") %></t>
<br><%# DataBinder.Eval(Container.DataItem, "catagorydescription") %><asp:Repeater ID="Repeater3" runat="server" DataSourceID="DataSourceMember"> <ItemTemplate> <br>Items: <%# DataBinder.Eval(Container.DataItem,"ItemName")%></t></t></t><%# DataBinder.Eval(Container.DataItem, "Amount") %> <br><%# DataBinder.Eval(Container.DataItem, "ItemDescription") %></br> </ItemTemplate> </asp:Repeater> <asp:SqlDataSource ID="DataSourceMember" runat="server" ConnectionString="server=myComp;uid=sa;pwd=sa;database=ItemCat" SelectCommand="SELECT \* FROM items where catID = '<%# DataBinder.Eval(Container.DataItem,"ID") %>'" \\> </ItemTemplate> <separatortemplate> <br /> <br /> <br /> </separatortemplate> </asp:Repeater>
erros is : Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. Parser Error Message: The server tag is not well formed. Source Error: Line 193: </ItemTemplate> Line 194: </asp:Repeater> Line 195: <asp:SqlDataSource ID="DataSourceMember" runat="server" ConnectionString="server=myComp;uid=sa;pwd=sa;database=ItemCat" SelectCommand="SELECT * FROM items [ACN] Where catID = '<%# DataBinder.Eval(Container.DataItem,"ID") %>'" \> Line 196:
suchita
modified on Monday, July 26, 2010 2:10 PM
-
I am taking datasource from the dataset which i passed it to the repeater1.I also tried like this:
<asp:Repeater runat="server" id="Repeater1">
<HeaderTemplate>items<br /><br /></HeaderTemplate>
<ItemTemplate>
<b><%# DataBinder.Eval(Container.DataItem, "catagoryname") %></t>
<br><%# DataBinder.Eval(Container.DataItem, "catagorydescription") %><asp:Repeater ID="Repeater3" runat="server" DataSourceID="DataSourceMember"> <ItemTemplate> <br>Items: <%# DataBinder.Eval(Container.DataItem,"ItemName")%></t></t></t><%# DataBinder.Eval(Container.DataItem, "Amount") %> <br><%# DataBinder.Eval(Container.DataItem, "ItemDescription") %></br> </ItemTemplate> </asp:Repeater> <asp:SqlDataSource ID="DataSourceMember" runat="server" ConnectionString="server=myComp;uid=sa;pwd=sa;database=ItemCat" SelectCommand="SELECT \* FROM items where catID = '<%# DataBinder.Eval(Container.DataItem,"ID") %>'" \\> </ItemTemplate> <separatortemplate> <br /> <br /> <br /> </separatortemplate> </asp:Repeater>
erros is : Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. Parser Error Message: The server tag is not well formed. Source Error: Line 193: </ItemTemplate> Line 194: </asp:Repeater> Line 195: <asp:SqlDataSource ID="DataSourceMember" runat="server" ConnectionString="server=myComp;uid=sa;pwd=sa;database=ItemCat" SelectCommand="SELECT * FROM items [ACN] Where catID = '<%# DataBinder.Eval(Container.DataItem,"ID") %>'" \> Line 196:
suchita
modified on Monday, July 26, 2010 2:10 PM
Now we finally get to the issue, "Parser Error Message: The server tag is not well formed". You could have saved a few steps and gave this information at the beginning. This is not the best way to accomplish this. You understand you are going to create a new SqlDatasource for each item in the parent list? Handle the ItemDataBound event of the parent repeater and assign the datasource, perferably from a cached source.
I know the language. I've read a book. - _Madmatt
-
Now we finally get to the issue, "Parser Error Message: The server tag is not well formed". You could have saved a few steps and gave this information at the beginning. This is not the best way to accomplish this. You understand you are going to create a new SqlDatasource for each item in the parent list? Handle the ItemDataBound event of the parent repeater and assign the datasource, perferably from a cached source.
I know the language. I've read a book. - _Madmatt
itemDataBound event is like this right:
void Repeater1\_ItemDataBound(object sender, RepeaterItemEventArgs e) { RepeaterItem item = e.Item; if ((item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingItem)) { Repeater3 = e.Item.FindControl("Repeater3"); DataRowView drv = (DataRowView)item.DataItem; Repeater3.DataSource = drv.CreateChildView("category\_item"); Repeater3.DataBind(); } }
but if i do like this, it give error as below: Repeater3 doesn't exits.. while ascx.cs code is
<asp:Repeater runat="server" id="Repeater1">
<HeaderTemplate>items<br /><br /></HeaderTemplate>
<ItemTemplate>
<b><%# DataBinder.Eval(Container.DataItem, "catagoryname") %></t>
<br><%# DataBinder.Eval(Container.DataItem, "catagorydescription") %><asp:Repeater ID="Repeater3" runat="server"> <ItemTemplate> <br>Items: <%# DataBinder.Eval(Container.DataItem,"ItemName")%></t></t></t><%# DataBinder.Eval(Container.DataItem, "Amount") %> <br><%# DataBinder.Eval(Container.DataItem, "ItemDescription") %></br> </ItemTemplate> </asp:Repeater> </ItemTemplate> <separatortemplate> <br /> <br /> <br /> </separatortemplate> </asp:Repeater>
suchita
-
itemDataBound event is like this right:
void Repeater1\_ItemDataBound(object sender, RepeaterItemEventArgs e) { RepeaterItem item = e.Item; if ((item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingItem)) { Repeater3 = e.Item.FindControl("Repeater3"); DataRowView drv = (DataRowView)item.DataItem; Repeater3.DataSource = drv.CreateChildView("category\_item"); Repeater3.DataBind(); } }
but if i do like this, it give error as below: Repeater3 doesn't exits.. while ascx.cs code is
<asp:Repeater runat="server" id="Repeater1">
<HeaderTemplate>items<br /><br /></HeaderTemplate>
<ItemTemplate>
<b><%# DataBinder.Eval(Container.DataItem, "catagoryname") %></t>
<br><%# DataBinder.Eval(Container.DataItem, "catagorydescription") %><asp:Repeater ID="Repeater3" runat="server"> <ItemTemplate> <br>Items: <%# DataBinder.Eval(Container.DataItem,"ItemName")%></t></t></t><%# DataBinder.Eval(Container.DataItem, "Amount") %> <br><%# DataBinder.Eval(Container.DataItem, "ItemDescription") %></br> </ItemTemplate> </asp:Repeater> </ItemTemplate> <separatortemplate> <br /> <br /> <br /> </separatortemplate> </asp:Repeater>
suchita
Repeater3 = e.Item.FindControl("Repeater3");
Of course it doesn't exist, what type is Repeater3? All you have is a name. You also understand FindControl needs to be cast to something useful?
I know the language. I've read a book. - _Madmatt
-
Repeater3 = e.Item.FindControl("Repeater3");
Of course it doesn't exist, what type is Repeater3? All you have is a name. You also understand FindControl needs to be cast to something useful?
I know the language. I've read a book. - _Madmatt
yes. i did like this:
Repeater3 =(Repeater) e.Item.FindControl("Repeater3");
now i have another error shown. The relation is not parented to the table to which this DataView points. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentException: The relation is not parented to the table to which this DataView points. Source Error: Line 120: Repeater2 = (Repeater)e.Item.FindControl("Repeater2"); Line 121: DataRowView drv = (DataRowView)item.DataItem; Line 122: Repeater2.DataSource = drv.CreateChildView("CategoryToItem"); Line 123: Repeater2.DataBind(); Line 124: }
suchita
modified on Monday, July 26, 2010 4:38 PM
-
yes. i did like this:
Repeater3 =(Repeater) e.Item.FindControl("Repeater3");
now i have another error shown. The relation is not parented to the table to which this DataView points. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentException: The relation is not parented to the table to which this DataView points. Source Error: Line 120: Repeater2 = (Repeater)e.Item.FindControl("Repeater2"); Line 121: DataRowView drv = (DataRowView)item.DataItem; Line 122: Repeater2.DataSource = drv.CreateChildView("CategoryToItem"); Line 123: Repeater2.DataBind(); Line 124: }
suchita
modified on Monday, July 26, 2010 4:38 PM
RTFM
I know the language. I've read a book. - _Madmatt
-
RTFM
I know the language. I've read a book. - _Madmatt
Sorry, I couldn't get that. Can you explain that please ? I even included below code:
SqlCommand objCmd = new SqlCommand(query, cnx);
SqlDataAdapter objDA = new SqlDataAdapter(objCmd);
DataSet ds = new DataSet();
objDA.Fill(ds);
Repeater1.DataSource = ds;
Repeater1.DataBind();DataColumn c1 = ds.Tables\["category"\].Columns\["ID"\]; DataColumn c2 = ds.Tables\["Items"\].Columns\["CatID"\]; dRel = new DataRelation("CategoryToItem", c1, c2); ds.Relations.Add(dRel);
suchita
-
RTFM
I know the language. I've read a book. - _Madmatt
ROFL A+ man A+ ... :-D
If at first you don't succeed ... post it on The Code Project and Pray.