Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting values from dynamically created Radio Button Lists

Status
Not open for further replies.
Feb 12, 2008
2
US
Hello,
I'm trying to create a quiz where there will be multiple lines of questions, pulled from a database. Each question will have several choices, only one of which will be selectable per line. The code I currently have is this

for each rw as datarow in ds1.tables("tblQuestions").rows
grpAnswers.id = "Question" & i
grpAnswers.Items.Add(New ListItem("Yes","1"))
grpAnswers.Items.Add(New ListItem("No","2"))
grpAnswers.Items.Add(New ListItem("Maybe","3"))
phQuiz.Controls.Add(grpAnswers)
i = i + 1
next

My question is, how do I get the selected value for each Radio Button List on the page? It looks like I have to use FindControl, but I'm not sure exactly how to write the code that I need. Any help would be appreciated. Thanks in advance.
 
because you are adding controls dynamically you need to add them with each postback. the other option is to declaratively define the answers in the markup, or bind an enumeration to the radiobuttonlist control.

depending on how your are displaying the questions will determine how to best configure the answers. (dynamically built, repeater, gridview, formview, etc.)



Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top