Nested repeater with 3 levels

Discussion in 'ASP .Net' started by Eirik Eldorsen, Feb 3, 2005.

  1. 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
     
    Eirik Eldorsen, Feb 3, 2005
    #1
    1. Advertising

  2. Eirik Eldorsen

    Karl Seguin Guest

    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" <> wrote in message
    news:%...
    > 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
    >
    >
     
    Karl Seguin, Feb 3, 2005
    #2
    1. Advertising

  3. 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:...
    > 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" <> wrote in message
    > news:%...
    >> 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
    >>
    >>

    >
    >
     
    Eirik Eldorsen, Feb 4, 2005
    #3
  4. Eirik Eldorsen

    acanel Guest

    (sorry but my english is so bad)
    hey, you can send me code?

    ()

    > 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" <> wrote in message
    > news:%...
    > 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
     
    acanel, Feb 20, 2005
    #4
  5. Eirik Eldorsen

    swestwood

    Joined:
    Sep 18, 2011
    Messages:
    1
    Hello, I have been looking for a solution only with 2 repeaters. Could you please send me the full code if you still have it?

    Many thanks
     
    swestwood, Sep 18, 2011
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sunil
    Replies:
    1
    Views:
    995
  2. Edwin Kusters

    Re: Multiple levels of Session Persistence

    Edwin Kusters, Jul 14, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    483
    John Saunders
    Jul 22, 2003
  3. Ed Allan
    Replies:
    1
    Views:
    774
    Ed Allan
    Jul 30, 2003
  4. Replies:
    0
    Views:
    903
  5. so.intech
    Replies:
    4
    Views:
    614
    so.intech
    Aug 9, 2006
Loading...

Share This Page