views:

126

answers:

5

What would be the best way to render list of many items (like comments that follow articles or blogs) on the web page from a database?

I've noticed in many sites 3 options:

  1. Table
  2. list of <ul> (ul under ul under ul...)
  3. list of <divs> (div under under div...)

And what asp.net control should i use?
Datalist, repeater?

+4  A: 

<ul> is the best, since it represents a list (and is therefore semantically correct - better for search engine optimization, for accessibility, etc.).

Among your Asp.Net control options, Repeater is the best by far, since it gives you complete control over the HTML you render - the other alternatives tend to produce extraneous markup and in some cases inline styles.

Jeff Sternal
+1  A: 

I prefer to use the Repeater in cases like this because it is very flexible. I've used it since 1.1 with all the combinations you've listed, and no problems so far!

I think the semantically correct markup tag choice for a comment list would be <ol> (ordered list), assuming your comments will be listed in ascending date order.

Josh Stodola
but what tags better to use? table? ul? divs?i can use any with repeater, but don't know what is better...
dani
I've updated my answer ;)
Josh Stodola
+1, `<ol>` is definitely the way to go when the content is ordered. (But beginners should be aware that these are numbered by default - if you don't want them numbered, be sure to set the list-style to whatever you prefer!)
Jeff Sternal
A: 

It depends on the structure of your data.

GridView - good for tabular data; few or no images required.

ListView - great for product-catalog type data. Great for images and linkage. Check out a great Listview tutorial by Scott Guthrie.

p.campbell
+1  A: 

I would use the <ul> tag because it is meant for lists. It is better for SEO purposes and you can create a hierchy such as a nested category.

I would not use the repeater or datalist. I would suggest using a MVC for loop. It is much faster then the repeater, grid and the datalist.

A: 

The short answer is, "it depends". Basically you should consider how your other site content is presented and stick with that (except if it sucks). However, the <ul> element is probably the most correct element to use for a list of items.

For asp.net controls I would recommend that you look at either the Repeater (as other have suggested), or if you want a more feature rich control, that still gives you total control over markup, the ListView control.

JohannesH