Collapsible Grid/Tree

M

mj2736

I have a pair of database tables with a structure similar to the
following:

--------------------------------------------
Table: Category
--------------------------------------------
CategoryID | CategoryName | ParentCategoryID

1 | 'A' | 0
2 | 'B' | 0
3 | 'AA' | 1
4 | 'AB' | 1
5 | 'BA' | 2
6 | 'BAA' | 5

-----------------------
Table: Budget
-----------------------
BudgetID | BudgetAmount

3 | $10
4 | $30
6 | $15

Hopefully it is clear that the Category table is a hierarchical tree
structure. Each Category record contains a parent ID that points to
another Category record in the same table. Categories with a parent ID
of 0 are at the top of the hierarchy, while a category that has a
non-zero parent ID is a sub-category. The categories without any
sub-categories have an associated record in the budget table. There is
no limit to how many levels deep the tree will go, and not all
categories will have the same number of levels of sub-categories.

I need to display this data as a table on a web form so that the
Categories can be expanded/collapsed to show/hide their sub-categories.
Also, when a category row is in a collapsed state, it should show the
sum of the amounts contained in its sub-categories.

I know there are 3rd party controls that can probably handle these
requirements, but it is preferred that this web form be built using
only the standard ASP.Net 2.0 controls. I've also come across a few
articles that describe nesting controls, but that's not exactly what I
want either... I don't want tables within tables, which would result in
columns that don't line up properly (there will actually be about a
dozen "amount" columns associated with each category), but just one
single table with the collapsed categories "hidden".

This seems like it would be a relatively common thing to do, but I
haven't been able to find any examples to get me started. How would you
recommend going about this? Which control would be best suited
(Repeater, DataList, DataGrid, GridView, etc)? Can the TreeView help me
at all? Would the GridView provide any benefits over the DataGrid in
this scenario? Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top