managing hierarchical data - categories

N

Neil McGuigan

Hi,

I want to store product categories in my db and am a little lost as to where
to start.

They can be hierarchical, such as "Books" > "Cook Books", so my table is
like this:

int CategoryId
int ParentCategoryId Nullable
string Description

with a foreign key from ParentCategoryId to CategoryId

I want to have the following functionality on my site:

list top level categories (those with no ParentCategoryId)
list subcategories of a category (1 level deep)
list full "path" of a category ("Books" > "Home Decorating" > "Criminals" >
"Martha Stuart")

put all the categories in a treeview control (don't know which one)
put all the categories in a select menu, like this:

<select>
<optGroup label="Books">
<option value="1">All</option>
<option value="3">Cooking</option>
<option value="99">Computers</option>
<optgroup label="Phones">
<option value=22>All></option>
<option value=44>Motorola</option>
</optgroup>
</optgroup>
<optgroup label="Cars">
<option value=5>All</option>
<option value=33>Mazdas</option>
</optgroup>
</select>

What is the best way to do this? I don't need help on how to display the
info once I have it, but I'd like to know how to efficiently retrieve it
from the database and store it in the appropriate data structure (pref C#).
I noticed the WebForms tree control has some of the functionality I want
such as the FullPath property, but there doesn't seem to be a similar one
for web forms. Thanks!

Neil M
 

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,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top