How can I enumerate a radiobuttonlist in .NET?
A:
Not really sure what you're asking here - but if you just want to enumerate thru the items, its...
foreach (var item in MyRbl.Items)
{
// do something with the current item.
}
If you're trying to get the value, just use .SelectedValue
If you're trying to do it client side to get the selected value - you could use jQuery to get the selected value...
var selected = jQuery('#<%= MyRbl.ClientID %> input:checked').val();
Scott Ivey
2009-05-01 16:05:32
+2
A:
foreach (ListItem item in RadioButtonList1.Items)
{
if (item .Selected == true)
{
Response.Write("You selected " + rbtn.Text);
}
}
womp
2009-05-01 16:07:27
I think this should be -> foreach(ListItem item in RadioButtonList1.Items){}
Phaedrus
2009-05-02 03:07:06
Good catch, thanks.
womp
2009-05-02 03:22:37
A:
RadioButtonList.Items is a ListItemCollection which implements IEnumerable.
Johan Öbrink
2009-05-01 16:07:29