I have a ASP.NET 4.0 application. I am building a Questionnaire kind of application. I have a Questionnaire.aspx page in which i will display the questions with answers(Multiple choice questions) retrieved from the database.
To display this i have created a asp:Panel control. Since i dont know the exact number of questions i am creating a Radiobuttonlist dynamically and adding it to the Asp:Panel.
The Questionnaire.aspx page have to display another set of questions based on the selection. So i have to recreate that RadiobuttonList with the new set of questions on a Button Click and display it in the same page.
The problem am facing is in retrieving the selectedItems of the previous set of questions.
I tried looping through the panel but the SelectedItem of the RadiobuttonList is empty(Because the page posted back)
Dayanithy
Member
4 Points
4 Posts
How to get SelectedItem of Dynamically Created RadioButtonList in codebehind
Jul 15, 2011 12:23 PM|LINK
Hi,
I have a ASP.NET 4.0 application. I am building a Questionnaire kind of application. I have a Questionnaire.aspx page in which i will display the questions with answers(Multiple choice questions) retrieved from the database.
To display this i have created a asp:Panel control. Since i dont know the exact number of questions i am creating a Radiobuttonlist dynamically and adding it to the Asp:Panel.
The Questionnaire.aspx page have to display another set of questions based on the selection. So i have to recreate that RadiobuttonList with the new set of questions on a Button Click and display it in the same page.
The problem am facing is in retrieving the selectedItems of the previous set of questions.
I tried looping through the panel but the SelectedItem of the RadiobuttonList is empty(Because the page posted back)
I tried the below code.
Dictionary<string, string> completeResultSet = new Dictionary<string, string>();
foreach (RadioButtonList list in Panel2.Controls.OfType<RadioButtonList>())
{
completeResultSet.Add(list.SelectedItem, list.SelectedValue);
}
Please suggest how to get the selected values. In which event i will be able to retrieve the list? Thanks in Advance
Dayanithy