Need help making a DataList and Repeater Work Nice together in layout.

Last post 11-17-2006 5:59 PM by ps2goat. 1 replies.

Sort Posts:

  • Need help making a DataList and Repeater Work Nice together in layout.

    09-19-2006, 11:51 PM
    • Loading...
    • rumblepup
    • Joined on 08-07-2003, 12:17 AM
    • Miami, Fl.
    • Posts 35

    Hello all.  Could use a little help.

    I have an e-commerce app where I created a stored proc to retrieve Parent and Child Categories, then I used a DataList for the Parent Cats, and a Repeater for the Sub-Cats.


    Works like a charm, but I can't style them correctly using a suckerfish css menu style I'd like to use.

     

    Here's my code:

     

    1    <asp:DataList id="dlMainCat" runat="server" DataKeyField="uid">
    2 <ItemTemplate>
    3 <A href=SearchResult.aspx?CategoryID=<%# DataBinder.Eval(Container.DataItem, "uid") %>><%# DataBinder.Eval(Container.DataItem, "Name") %></a>
    4 <asp:Repeater id="rptSubCategory" runat="server">
    5 <ItemTemplate>
    6 <A href=SearchResult.aspx?CategoryID=<%# DataBinder.Eval(Container.DataItem, "uid") %>><%# DataBinder.Eval(Container.DataItem, "Name") %></A>
    7 </ItemTemplate>
    8 </asp:Repeater>
    9 </ItemTemplate>
    10 </asp:DataList>

     My problem is this

    On line 3, I have the first line of the Parent Categories

    On line 4, I insert my repeater for the Sub-Categories

    Ok, my problem is this, I wan to list these as a list

    <ul>

    <li>Parent Cat</li>

        <ul>

            <li>Sub-Cat</li>

         </ul>

    </ul>

    But I can't wrap my head around it.

    Where do I introduce the <ul> tag then the <li> tag?

    Any help?
     

    Paranoid. Nah, it's just that everybody is out to get me.
    Filed under: , , ,
  • Re: Need help making a DataList and Repeater Work Nice together in layout.

    11-17-2006, 5:59 PM
    • Loading...
    • ps2goat
    • Joined on 11-17-2006, 5:43 PM
    • Posts 1,651

    There may be a problem if you're using VS 2005 versus 2003.  2005 is more strict on XHTML coding standards that are built in, whereas 2003 was more lax.  In any case, you may be able to set you <!DOCUMENT> type to transitional for this to work.  I've read that the Repeater control is technically the only control you can break up html in, and I'm not sure about whether the validation schema will let you put a repeater object inside a <ul>. 

    Anyway, enough babbling; Here's your code:

     

     

    <ul>
    <asp:DataList id="dlMainCat" runat="server" DataKeyField="uid">
    <ItemTemplate>
    <li>
    <a href='SearchResult.aspx?CategoryID=<%# DataBinder.Eval(Container.DataItem, "uid") %>'><%# DataBinder.Eval(Container.DataItem, "Name") %></a>
    <ul>
    <asp:Repeater id="rptSubCategory" runat="server">
    <ItemTemplate>
    <li>
    <a href='SearchResult.aspx?CategoryID=<%# DataBinder.Eval(Container.DataItem, "uid") %>'><%# DataBinder.Eval(Container.DataItem, "Name") %></a>
    </li>
    </ItemTemplate>
    </asp:Repeater>
    </ul>
    </li>
    </ItemTemplate>
    </asp:DataList>
    </ul>

     

     

    P.S. I just typed all the code in VS 2005, and it didn't seem to mind the DataList being nested in the <ul> tag.  I hope this helps you out, even though it's been a while since you posted...

    ---------------------------------------
    MCP - Web Based Client Development .NET 2.0
Page 1 of 1 (2 items)
Microsoft Communities
Page view counter