By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,296 Members | 1,564 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,296 IT Pros & Developers. It's quick & easy.

Nested repeater with 3 levels

P: n/a
Im trying to make a nested repeater with 3 levels. I've successfully created
a nested repeater with 2 levels, but when adding the 3rd level I get an
InvalidCastException. What am I doing wrong?
Here is my code:
<asp:Repeater id="level1Repeater" runat="server">
<itemtemplate>
<a href="#"><%# DataBinder.Eval(Container.DataItem, "Title") %></a>
<br>
<asp:repeater id="level2Repeater" runat="server" datasource='<%#
((DataRowView)Container.DataItem).Row.GetChildRows ("L1L2") %>' >
<itemtemplate>
&nbsp;<a href="#"><%# DataBinder.Eval(Container.DataItem,
"[\"Title\"]")%></a>
<br>
<asp:repeater id="level3Repeater" runat="server"
datasource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows ("L2L3")
%>' >
<itemtemplate>
&nbsp;&nbsp;<a href="#"><%#
DataBinder.Eval(Container.DataItem, "[\"Title\"]")%><br></a>
</itemtemplate>
</asp:Repeater>
</itemtemplate>
</asp:Repeater>
</itemtemplate>
</asp:Repeater>

Code Behind:

private void BindWebsites()
{
level1Repeater.DataSource = Websites.GetAll();
Page.DataBind();
}

public static DataTable GetAll()
{
.......
ds.Relations.Add("L1L2", ds.Tables["WebsitesL1"].Columns["ID"],
ds.Tables["WebsitesL2"].Columns["ParentID"]);
ds.Relations.Add("L2L3", ds.Tables["WebsitesL2"].Columns["ID"],
ds.Tables["WebsitesL3"].Columns["ParentID"]);

return ds.Tables["WebsitesL1"];
}
--
Eirik Eldorsen
Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Erik:
Weird, everything looks good...While you shouln't have to, maybe if you move
the nesting to the OnItemCommand event you'll figure out hte problem:
http://openmymind.net/databinding/index.html#7.2

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Eirik Eldorsen" <ku*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Im trying to make a nested repeater with 3 levels. I've successfully created a nested repeater with 2 levels, but when adding the 3rd level I get an
InvalidCastException. What am I doing wrong?
Here is my code:
<asp:Repeater id="level1Repeater" runat="server">
<itemtemplate>
<a href="#"><%# DataBinder.Eval(Container.DataItem, "Title") %></a> <br>
<asp:repeater id="level2Repeater" runat="server" datasource='<%#
((DataRowView)Container.DataItem).Row.GetChildRows ("L1L2") %>' >
<itemtemplate>
&nbsp;<a href="#"><%# DataBinder.Eval(Container.DataItem,
"[\"Title\"]")%></a>
<br>
<asp:repeater id="level3Repeater" runat="server"
datasource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows ("L2L3")
%>' >
<itemtemplate>
&nbsp;&nbsp;<a href="#"><%#
DataBinder.Eval(Container.DataItem, "[\"Title\"]")%><br></a>
</itemtemplate>
</asp:Repeater>
</itemtemplate>
</asp:Repeater>
</itemtemplate>
</asp:Repeater>

Code Behind:

private void BindWebsites()
{
level1Repeater.DataSource = Websites.GetAll();
Page.DataBind();
}

public static DataTable GetAll()
{
.......
ds.Relations.Add("L1L2", ds.Tables["WebsitesL1"].Columns["ID"],
ds.Tables["WebsitesL2"].Columns["ParentID"]);
ds.Relations.Add("L2L3", ds.Tables["WebsitesL2"].Columns["ID"],
ds.Tables["WebsitesL3"].Columns["ParentID"]);

return ds.Tables["WebsitesL1"];
}
--
Eirik Eldorsen

Nov 19 '05 #2

P: n/a
Thank you!

I moved the nesting to the OnItemDataBound event, and now everything works
:-D
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
skrev i melding news:Ol**************@tk2msftngp13.phx.gbl...
Erik:
Weird, everything looks good...While you shouln't have to, maybe if you
move
the nesting to the OnItemCommand event you'll figure out hte problem:
http://openmymind.net/databinding/index.html#7.2

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Eirik Eldorsen" <ku*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Im trying to make a nested repeater with 3 levels. I've successfully

created
a nested repeater with 2 levels, but when adding the 3rd level I get an
InvalidCastException. What am I doing wrong?
Here is my code:
<asp:Repeater id="level1Repeater" runat="server">
<itemtemplate>
<a href="#"><%# DataBinder.Eval(Container.DataItem, "Title")

%></a>
<br>
<asp:repeater id="level2Repeater" runat="server" datasource='<%#
((DataRowView)Container.DataItem).Row.GetChildRows ("L1L2") %>' >
<itemtemplate>
&nbsp;<a href="#"><%# DataBinder.Eval(Container.DataItem,
"[\"Title\"]")%></a>
<br>
<asp:repeater id="level3Repeater" runat="server"
datasource='<%#
((DataRowView)Container.DataItem).Row.GetChildRows ("L2L3")
%>' >
<itemtemplate>
&nbsp;&nbsp;<a href="#"><%#
DataBinder.Eval(Container.DataItem, "[\"Title\"]")%><br></a>
</itemtemplate>
</asp:Repeater>
</itemtemplate>
</asp:Repeater>
</itemtemplate>
</asp:Repeater>

Code Behind:

private void BindWebsites()
{
level1Repeater.DataSource = Websites.GetAll();
Page.DataBind();
}

public static DataTable GetAll()
{
.......
ds.Relations.Add("L1L2", ds.Tables["WebsitesL1"].Columns["ID"],
ds.Tables["WebsitesL2"].Columns["ParentID"]);
ds.Relations.Add("L2L3", ds.Tables["WebsitesL2"].Columns["ID"],
ds.Tables["WebsitesL3"].Columns["ParentID"]);

return ds.Tables["WebsitesL1"];
}
--
Eirik Eldorsen


Nov 19 '05 #3

P: n/a
(sorry but my english is so bad)
hey, you can send me code?

(ac****@gmail.com)
Karl Seguinwrote: Erik: Weird, everything looks good...While you shouln't have to, maybe if you move the nesting to the OnItemCommand event you'll figure out hte problem: http://openmymind.net/databinding/index.html#7.2

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Eirik Eldorsen" <ku*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Im trying to make a nested repeater with 3 levels. I've successfully created
a nested repeater with 2 levels, but when adding the 3rd level I get an InvalidCastException. What am I doing wrong?
Here is my code:
asp:Repeater id="level1Repeater" runat="server"
itemtemplate
a href="#"><%# DataBinder.Eval(Container.DataItem, "Title")
%></a
br
asp:repeater id="level2Repeater" runat="server" datasource='<%#
((DataRowView)Container.DataItem).Row.GetChildRows ("L1L2") %>'
itemtemplate
<a href="#"><%# DataBinder.Eval(Container.DataItem, "[\"Title\"]")%></a
br
asp:repeater id="level3Repeater" runat="server"
datasource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows ("L2L3") %>'
itemtemplate
<a href="#"><%#
DataBinder.Eval(Container.DataItem, "[\"Title\"]")%><br></a /itemtemplate
/asp:Repeater
/itemtemplate
/asp:Repeater
/itemtemplate
/asp:Repeater

Code Behind:

private void BindWebsites()
{
level1Repeater.DataSource = Websites.GetAll();
Page.DataBind();
}

public static DataTable GetAll()
{
.......
ds.Relations.Add("L1L2", ds.Tables["WebsitesL1"].Columns["ID"],
ds.Tables["WebsitesL2"].Columns["ParentID"]);
ds.Relations.Add("L2L3", ds.Tables["WebsitesL2"].Columns["ID"],
ds.Tables["WebsitesL3"].Columns["ParentID"]);

return ds.Tables["WebsitesL1"];
}
--
Eirik Eldorsen

[/quote:a689f73dce]

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.