C# Developers' Journal (original) (raw)

7:40p

Long time lurker here with 2 confusing questions:

Question 1:

I'm writing a web app in C#/ASP.NET 1.1. In one section of it I have an ASP:Table. I want to dynamically add rows to it based off the contents of a database table that has 3 fields. In each row there are 2 cells, the first has a label containing the contents of one of the fields in the table. In the second cell, there needs to be a drop-down that gets filled with data based off the 2nd field in the row from the table used to fill the label in the first cell.

That's all pretty confusing, so I'll try to diagram it.

The database:

ID Name ParentId
1 Colors null
2 Shapes null
3 Green 1
4 Blue 1
5 Circle 2
6 Square 2

As you can see the table has a hierarchy inside it. The parents (rows with null in the ParentID field) would have their names put into the label in the first cell. Then the dropdown would have options in it for each child. For example:

Colors <select ... ><option ... >Green<option ... >Blue
Shapes <select ... >Circle<option ... >Square

(I doubt LJ will allow the dropdowns to be posted, but it's worth a shot)

Now I could hard-code this easily, however I want it to be dynamic - so, for example, if I were to suddenly want to add in a "Pattern" option I could, and the page would automatically add in a new row, complete with label and drop-downs.

Question 2 - Along the same lines as Question 1 - When a new option is selected on one of the dropdowns added in Question 1, how would I go about giving it a function to perform? All the dropdowns would use the same function, provided I could pass the value of the freshly selected index to it.

Any advice on how to go about doing these would be spectacular. If you have questions, I unfortunately might be delayed in responding, as I just moved and won't have an internet hookup till Wednesday. I get to deal with the Starbucks crowd when I want to get online till then ;)