views:

268

answers:

5

I have some data that must be presented in tabular form with multiple sections. In particular, Each section of data is broken up (with it's own headers) by day. This is basically a one-off single page deal, and won't really be maintained, so I don't want to put a lot of effort into architecture.

I have two tables. HEADERS and ITEMS.

HEADERS have a format of:

date(datetime), type(tinyint), firstline(varchar), secondline(varchar)

ITEMS has a format of

id(int), date(datetime), type(tinyint), name(varchar), value1(int), 
    value2(int), value3(int)

I need the data to look similar to this (first and secondline are data populated, third line is static text, item lines are data populated):

1/1/2009
--------------------------------------------------------------------------
|                              [First line]                              |
--------------------------------------------------------------------------
|                             [Second line]                              |
--------------------------------------------------------------------------
|  Date |       Name            |   Value 1    |   Value 2   |  Value 3  |
==========================================================================
| [Date]|      [Name]           |  [Value 1]   |  [Value 2]  | [Value 3] |
--------------------------------------------------------------------------
| [Date]|      [Name]           |  [Value 1]   |  [Value 2]  | [Value 3] |
--------------------------------------------------------------------------
1/2/2009
--------------------------------------------------------------------------
|                              [First line]                              |
--------------------------------------------------------------------------
|                             [Second line]                              |
--------------------------------------------------------------------------
|  Date |       Name            |   Value 1    |   Value 2   |  Value 3  |
==========================================================================
| [Date]|      [Name]           |  [Value 1]   |  [Value 2]  | [Value 3] |
--------------------------------------------------------------------------
| [Date]|      [Name]           |  [Value 1]   |  [Value 2]  | [Value 3] |
--------------------------------------------------------------------------

This will repeat for all days currently in the database, each day having it's own table with it's own headers. They will also be filtered by type. the page will only show headers and items of the type specified. Type is an tinyint.

So the question is, What is the best ASP.NET elements to use? DataList? GridView? And how do I include the data from two tables in a header/item format?

EDIT: Sorry, forgot to mention that this has to work on Windows 2000/IIS5, so i'm stuck with ASP.NET 2.0 and can't use 3.0 or 3.5 features.

+1  A: 

I would recommend returning the data as XML then using an XSLT to build your report. Otherwise you will have to use nested GridViews or repeaters.

David
+2  A: 

Have a look at asp:table. You can programmaticaly add the rows and columns in some nested conditional iterations in code.

grenade
+1  A: 

If the pattern holds true everytime with the same number of lines, etc. A repeater may be your best bet and give you the most control over how the layout looks on the screen.

RSolberg
+1  A: 

Place an <asp:Table> on the page and build it up from code behind.

Use the colspan parameter for the columns (cells) as this allows you to create entries that span across many columns for the rows that need to.

For your app above, this would mean that First Line and Second Line would have a colspan of 5.

BenB
A: 

Ok, heres the eventual solution I came up with. I'm sure this is not the most efficient, or the fastest, but I just needed to get it done and move on with something else.

My first step was to create a base class, which I called RowBase, this was an abstract class which implemented an abstract method called GetRow(); Then I derived two other classes, BannerRow and ItemRow from RowBase. These classes contain fields with all the data used in my tables.

I then created two DataTables, and filled them with the results of my two queries via a DataAdapter.

Next, I created a List<RowBase> and interated over the datatables, creating either a BannerRow or ItemRow depending on the type of row.

Next, I ran a List<RowBase>.Sort, sorting on date and type of row to make sure that BannerRows hand priority over ItemRows.

Finally, I created placed a table on my webform, set it to runat="server" with an id="maintable" and then I iterated over my List<RowBase> and called GetRow on each RowBase.

BannerRow and ItemRow each had an override of GetRow() that returned an HtmlTableRow formatted to include the data in the correct format. Then, I used some conditional logic to insert header rows for the ItemRow data all worked out.

This is a variation of Rob and Ben's idea, but included a lot more massaging of the data, so I gave both of them upvotes, but am crediting myself with the answer.

Mystere Man