Solved

Datalist spacing problem in asp.net

Posted on 2007-04-10
5
346 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 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