Solved

Datalist spacing problem in asp.net

Posted on 2007-04-10
5
345 Views
Last Modified: 2013-11-07
I'm trying to display a list of categories and sub categories in two columns.  I've got it working, but one thing I can't figure out is how to get rid of the excess spacing.  Basically if in the left column the first category only has 1 sub category and the category next to that on the right has 8, then there is a lot of empty space between categories on the left.

I've tried changing things like repeatlayout etc, but unfortunately I haven't had much luck.

I hope this makes sense.  

Here's my code:

-------------------

<asp:datalist id="MainCat" runat="server" onitemdatabound="MainCat_ItemDataBound" repeatcolumns="2" itemstyle-width="381px" itemstyle-verticalalign="Top">
<ItemTemplate>

<strong><a href='category.aspx?MainCategory=<%#DataBinder.Eval(Container.DataItem, "HBI_CAT_ID")%>'><%#DataBinder.Eval(Container.DataItem, "HBI_CAT_NAME")%></a></strong><br />

    <asp:repeater id="SubCat" datasource='<%# Container.DataItem.Row.GetChildRows("myrelation") %>' runat="server">

        <itemtemplate>
            &nbsp;&nbsp;&nbsp;- <a href='category.aspx?SubCategory=<%#Container.DataItem("HBI_SUBCAT_ID")%>'><%#Container.DataItem("HBI_SUBCAT_NAME")%></a><br />
        </itemtemplate>

        <footertemplate>
            <br />
        </footertemplate>

    </asp:repeater>


</ItemTemplate>


My results currently display like this:

Cat 1                          Cat3
Sub cat 1                    Sub cat 1
                                  Sub cat 2
                                  Sub cat 3
                                  Sub cat 4
                                  Sub cat 5

Cat 2
Sub cat 1

But I would like them to display like this:

Cat 1                          Cat3
Sub cat 1                    Sub cat 1
                                  Sub cat 2
Cat 2                          Sub cat 3
Sub cat 1                    Sub cat 4
                                  Sub cat 5

thanks

0
Comment
Question by:Saroj13
5 Comments
 
LVL 12

Expert Comment

by:craskin
ID: 18885523
i believe the datalist uses tables instead of div tags to render out (you can check by viewing the source once you've browsed to it). if so, i don't think there could be a way around it other than using a repeater and doing the layout yourself.
0
 
LVL 27

Accepted Solution

by:
Sammy earned 500 total points
ID: 18885687
The most elegant way to to this is by using CSS adapters
you can look at them here
http://www.asp.net/cssadapters/
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question