views:

31

answers:

2

What is the best method to display repeating data with slightly different controls or sub data? For example displaying an expanded list of questions and answers. Some questions will have answers, some will not. Some button controls would show for some items while not for others.

In classic ASP I've used XML/XSL quite effectively for displaying data in this manner. In .NET I've used functions being called from a label with the HTML writer class to render controls dynamically and nested list views that would bind or not depending on existing data.

I know I could also use XSL with .NET but my question is - is there a better method of displaying data this way? Inline IIf's and functions being called from the front end doesn't seem very clean.

+1  A: 

I think the ListView would work in your situation:

http://blogs.msdn.com/mikeormond/archive/2008/01/23/some-asp-net-3-5-listview-control-examples.aspx

http://weblogs.asp.net/scottgu/archive/2007/08/10/the-asp-listview-control-part-1-building-a-product-listing-page-with-clean-css-ui.aspx

You have the ability to group items in different layouts using the ItemTemplates and you can also tap into the event handlers when loading the data.

EDIT:

You may be able to do it this way dynamically, but it's tricky with the ID's: http://blogs.msdn.com/mikeormond/archive/2008/07/26/dynamically-loading-listview-templates.aspx

Or you could simply create a table composite control and build it up dynamically yourself...

IrishChieftain