Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 24, 2011 10:46 PM by antonyliu2002
Jun 24, 2011 08:20 PM|LINK
In a project of mine, I need to dynamically present something like shown in the screenshot below. (Anything in red is not gonna be in the web form, they only help me clarify my issue)
The number of categories is uncertain, it can be 1 or many.
The number of list items is uncertain, it can be 1 or many.
And of course, upon post back, I need to capture the SelectedValues of each RadioButtonList so I can do something about the user selections.
Any strategy? User control? Customized server control?
Jun 24, 2011 08:45 PM|LINK
I think a user control with a few properties would do the best job. You would need a way to set the datasource for the radiobuttonlist (which appears to always be the same) then for each category add a new user control and the category and selected item would
also be a properties. One problem I see with this is you can only go right so much before you run out of space. If you can't imagine having more then 5 categories it's probably fine but otherwise it may be a problem.
Anyway if you use a user control with a way to set the datasource through a property or method and then set and get the selected value and category I think it will be pretty straight forward.
Jun 24, 2011 10:46 PM|LINK
Thank you for sharing your idea.
Yes, I thought about it and implemented it just like your idea.
To horizontally layout the RadioButtonLists, I am using an <asp:Table /> control and dynmically add cells to a TableRow and add the dynmically created RadioButtonList to the cells.
In order to get the SelectedValue(s) of all the RadioButtonList(s), I implemeted a public property:
public Dictionary<string, string> SelectedValues
// Iterate through all the radio button lists and add the selected values to a dictionary and return it.
// The key of the dictionary is the ID of the radio button list and the value is the selected value of this radio button list.
So far, it works fine.