views:

72

answers:

2

Hi,

I have a repeater which looks like so:

<HeaderTemplate>
    <div>
</HeaderTemplate>
<ItemTemplate>
<asp:PlaceHolder runat="server" id="plhContent"/>
</ItemTemplate>
<FooterTemplate>
    </div>
</FooterTemplate>

I then have a dataset that looks like:

Title | Category
"Title1","Legal"
"Title2","Legal"
"Title3","Finance"
"Title4","Accounting"

The dataset is sorted by the category.

And the output im trying to achieve is:

<div><!-- from headertemplate -->
    <div id="legal">
        <ul>
            <li>Title 1</li>
            <li>Title 2</li>
        </ul>
    </div><!--end legal div-->
    <div id="Finance">
        <ul>
            <li>Title 3</li>
        </ul>
    </div><!--end finance div-->
    <div id="Accounting">
        <ul>
            <li>Title 4</li>
        </ul>
    </div><!--end accounting div-->
</div><!-- from footertemplate -->

However I'm really struggling with the logic. Within my code i've essentially got:

Add a bulleted list
Add a listitem

But this poses a problem for the row "title2" because it doesnt require a new bulleted list, it just requires a new listitem to be added to the bulleted list in the previous iteration of the repeater.

How can i possibly do this?

Thanks in advance Al

+1  A: 

An option would be to create some kind of temporary structure to hold the contents of the DataSet in a way that the Repeater will be able to handle to display the information the way you need it.

I'm thinking about turning it into a list of categories, and each category will be a list of items. Then you go through the DataSet items like so (pseudo-code):

for each item if category does not exist in list of categories create a list of "category items" add the item (title) to the list add this list to the list of categories else find the category add the item (title) to the list

The repeater should then be able to handle it

Farinha
A: 

You could implemented a nested repeater see the following link for a good example

http://www.worldofasp.net/tut/NestedRepeater/Repeater_within_Repeater_193.aspx

Ivo