I would probably contain all the radio button lists for the various questions within a panel to make it easier to only loop through these rather than any other radio button lists you may have on the page. I would then do something like this for the single button click event:
protected void btnSubmit_Click(object sender, EventArgs e)
{
//Store the question number and answer.
Dictionary<int, string> Answers = new Dictionary<int, string>();
//Loop through the radio button lists within your panel
int i = 1; //used to determine the question number
foreach (var rdbl in MyPanel.Controls.OfType<RadioButtonList>())
{
Answers.Add(i, rdbl.SelectedValue.ToString());
i++;
}
//Do something with your stored answers.
}
I’ve not tested this code so let me know how you get on with it. Also, it would be easier to make this more specific to your scenario if you were to post your aspx code that you have.
UPDATE
To reference your div tag in the code behind (instead of using MyPanel) you need to make sure the div looks something like this:
<div ID="MyDiv" runat="server">
This should allow you to reference the div in the code behind simply by using ‘MyDiv’. See here for further examples.
14
solved How to use dictionary in c#? [closed]