Blankman
Blankman

Reputation: 267370

How can I enumerate a radiobuttonlist in .NET?

How can I enumerate a radiobuttonlist in .NET?

Upvotes: 1

Views: 1259

Answers (4)

womp
womp

Reputation: 116987

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

Upvotes: 3

Johan Öbrink
Johan Öbrink

Reputation: 1291

RadioButtonList.Items is a ListItemCollection which implements IEnumerable.

Upvotes: 0

Scott Ivey
Scott Ivey

Reputation: 41588

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

Upvotes: 0

Jamie Ide
Jamie Ide

Reputation: 49301

Enumerate its Items collection.

Upvotes: 0

Related Questions