views:

4029

answers:

5

For full control of your application, do you prefer a GridView or a HTML table? And why?

For instance, I need to create on-the-fly hyperlinks-per-row in a GridView/HTML table. What object would be more easy to add that feature (or others like this one)?

Note: I'm creating programmatically my datasets

+5  A: 

If you don't need the built in support for sorting or paging, and want more control over the rendered output then I would consider using a Repeater control to output a table. If you need the built in sorting/paging then the GridView can be very helpful.

If you want the best of both worlds, upgrade to ASP.net 3.5 and use the ListView.

EDIT: Can you clarify what you mean by 'on-the-fly hyperlinks-per-row'?

AJ
'on-the-fly hyperlinks-per-row'= create some hyperlinks in some cells
Armadillo
+1  A: 

I think the Repeater or the newer ListView is the way to go if you don't need sorting and/or paging. The Repeater and ListView allow you to control the HTML (the GridView is a total black box in this regard and generates atrocious HTML) while avoiding the tedious server-side code that comes with the <asp:Table> control: "OK, new row. New cell. Do something with cell. Add cell to row. Add row to table. Repeat".

On the other hand, if you need paging and sorting, the GridView is probably the better solution.

Matt Peterson
A: 

You can use GridView or more simple Repeater-like controls to build your own html, even if you have to sort/page you data. With a Repeater for example you can build a custom system of pagination using a PagedDataSource data source with the property AllowPaging sets to true.

The only problem is clearly that with a simple Repeater you must write more code to do the work that GridView does natively.

But the result is faster.

tanathos
A: 

Stay away from the Gridview. It has to pull down the entire dataset to render the paging. It's much faster to render only the rows you need (e.g. rows 30 - 40 of 6,0000) and use a seperate pager control. Also when it comes to HTML/CSS, using a repeater or listview will be much easier to debug, since you'll have total control over the code.

Mike Robinson
A: 

A plain HTML <table> generated by Response.Write is straightforward and has the added benefit that if you ever work on a non-Microsoft system, you won't feel naked without their redundant ASP.NET web controls that mostly just make it more difficult to generate the HTML everyone already knows.