Tutorial :How can I enumerate a radiobuttonlist in .NET?



Question:

How can I enumerate a radiobuttonlist in .NET?


Solution:1

foreach (ListItem item in RadioButtonList1.Items)  {      if (item .Selected == true)      {         Response.Write("You selected " + rbtn.Text);      }  }  


Solution:2

Enumerate its Items collection.


Solution:3

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();  


Solution:4

RadioButtonList.Items is a ListItemCollection which implements IEnumerable.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »