views:

46

answers:

2

Hi folks,

I want to copy StackOverflow's TAG's page, where they have a list of Tags (or whatever) and display them into a few columns, with the first column being the first 10 records, the second column being record 11->20 .. etc.

and of course I have my data already paged.

I'm not sure what this type of view is called? is this a grid view? to me, grid views are like excel sheets ... with all the data in rows and the columns are for filtering/sorting.

Can anyone help?

A: 

If you check the HTML source of that page, you'll see that SO does it using a table. You can do that with some sort of grid helper, or just straight in the View if you wanted.

You can do that very simply in the view by just figuring out how many columns you want, and how many items you want in each row. Enumerate the whole result set, and every X items (X being the max-per-column value) create a new TD tag. Of course, then make sure each page of data does not exceed X * COLUMNS

But since you don't want to do it with tables, this answer probably won't help you.

Andrew Barber
Yeah, I know it's a table (or infact, it should really be divs .. tables are so 1990's..) .. but i was hoping for some code or some links to some tutorials that could show me how they divide up the data into columns before displaying them to the view.
Pure.Krome
Tables have a purpose; displaying tabular data. That's exactly what that is: tabular data. It is exactly what tables are for. BTW; the `A` tag is from the 1990's, too... should we stop using it for links?
Andrew Barber
:) I'm not about to get into a debate about tables vs div's :)
Pure.Krome
Then I can't really help you. You want something with 'columns' and 'rows', but don't want a table; Why not do it with `UL` or `CODE` tags? (being facetious, for the dense)
Andrew Barber
Tables so last century? No way. Tables are for tabular data. "Bad" tables are layout tables. But tables with tabular data is the correct structure.
awrigley
A: 

You could use a GridView, but you could also get away with using a ListView, which allows for a little more control over your markup. You could, for example, do something like this:

        <asp:ListView>
            <LayoutTemplate>
                <table border="0" cellpadding="1">
                    <asp:ContentPlaceHolder ID="itemPlaceHolder" runat="server" />
                </table>
            </LayoutTemplate>
            <ItemTemplate>
                <tr>
                    <td>
                        <asp:Label runat="server" class="lbl_tag"><%#Eval("Tag") %></asp:Label>
                    </td>
                    <td>
                        <asp:Label runat="server" class="lbl_tag"><%#Eval("Tag") %></asp:Label>
                    </td>
                    <td>
                        <asp:Label runat="server" class="lbl_tag"><%#Eval("Tag") %></asp:Label>
                    </td>
                </tr>
            </ItemTemplate>
        </asp:ListView>

This would give you three columns of "tags". ListView also has some nice properties like the AlternatingItemTemplate. And if you don't want your ListView to render as a table, you can simply modify your template with your own markup. Of course, as I said, you could just as easily use a GridView for this type of thing.

Tyler
You could use a ListView or Gridview, but I wouldn't recommend doing so in ASP.NET MVC.
Andrew Barber
Agreed @Andrew Barber - i want to avoid classic asp control where possible.
Pure.Krome
@Pure.Krome, these are ASP.NET controls, not Classic. And all they're used to do is dynamically generate HTML, but if you'd rather have static code, then why not just hardcode a table? If you're so against tables (which is silly -- tables are for tabular data), then just use divs.
Tyler
@ttreat31 - i'll post up my answer but i got it working really easily (yesterday) with a div + ul's - just like our UI guys love and request.
Pure.Krome