views:

25

answers:

1

Hello

I have few monhts working with aspx, and now I'm developing a shopping cart website. For the employee to upload the products on the DB, every product needs to be linked to a category and sub category, and sub-sub category, and so on. Sometimes the sub-sub categories are up to 5. For example Electronics-TV-LCD-Samsung-40 inches.

First, What I would like to identify is if the SQL table has the apporpiate structure. I have 3 columns Id, Description, Parent_Id. Categories with Parent Id=0 is used for the top ones. Is this the best way to do it?

Then I want to use the ListBox control to select main Categories, and once it is selected, filled a second listbox with its childs and so on. Do I need to query SQL DB everytime the change event happens? I heard about linq but have not used yet, What would be your suggestion to do this. If you have seen a sample to understand it better will be appreciated.

Thank you

A: 

I would say that the category table structure is sensible. There are a number of ways to implement the interface. You could populate the child listboxes without a call to the database, but you would have to retrieve the entire hierarchy with every page refresh and store them in javascript arays or similar and then populate the child listboxes using javascript, this might be a lot of extra data if is a comples category hierarchy. You could also set the autopostback=true propertyon the listbox and it will postback to the server every time the selection changes,this is a bit clunky though. A middle ground would be to use ajax. The easiest way to do this is to use update panels, just design it the postback way and wrap your listboxes in update panels. The most eficient way would be to write a web service to return a list of categories and wire it up using a scriptmanager control. You can then call it using javascript and poulate your listboxes with the data returne by the web service.

Ben Robinson