I have a HTML form
that has multiple RadioButtonLists
.
<div>
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Value="1" Text="1"></asp:ListItem>
<asp:ListItem Value="2" Text="2"></asp:ListItem>
</asp:RadioButtonList>
</div>
<div>
<asp:RadioButtonList ID="RadioButtonList2" runat="server">
<asp:ListItem Value="3" Text="3"></asp:ListItem>
<asp:ListItem Value="4" Text="4"></asp:ListItem>
</asp:RadioButtonList>
</div>
<div>
<asp:RadioButtonList ID="RadioButtonList3" runat="server">
<asp:ListItem Value="5" Text="5"></asp:ListItem>
<asp:ListItem Value="6" Text="6"></asp:ListItem>
</asp:RadioButtonList>
</div>
<div>
<asp:RadioButtonList ID="RadioButtonList4" runat="server">
<asp:ListItem Value="7" Text="7"></asp:ListItem>
<asp:ListItem Value="8" Text="8"></asp:ListItem>
</asp:RadioButtonList>
</div>
How can I iterate through each RadioButtonList
to select each value?
This is what I have got so far, am I on the right track or is there a better way to do this?
int value1= 0;
int value2= 0;
if (RadioButtonList1.SelectedValue == "1")
{
value1++;
}
else if (RadioButtonList1.SelectedValue == "2")
{
value2++;
}
if (RadioButtonList2.SelectedValue == "1")
{
value1++;
}
else if (RadioButtonList2.SelectedValue == "2")
{
value2++;
}
I have also tried this but cant seem to get it all correct
foreach(RadioButtonList rbl in ?????)
{
if (rbl.SelectedValue == "1")
{
value1++;
}
else if (rbl.SelectedValue == "2")
{
value2++;
}
}
Any help or point in the right direction would be very helpful!
Thanks