Skip to content
December 21, 2010 / pauldundon

Using Radio Buttons in ASP.NET ListView

The requirement

Use radio buttons to select between items in a ListView

The problem

If you use ASP.NET radio buttons, the framework renders each radio button with a distinct name attribute so that they do not function as a group. This means that users can select all the radio buttons, and not just one.

Possible solution

Use ordinary HTML radio buttons bound as follows:

<input type="radio" name="listViewSelect" value='<%# Eval("RecordID") %>' />

You can use any value for the name attribute. Where this code has “RecordID” you need any field you can use to distinguish one item from another. To determine which item was selected, use something like the following to retrieve the value of RecordID:

Dim selection As String = Request.Form("listViewSelect")

Limitations

The radio button will not raise events.

Advertisements

One Comment

Leave a Comment
  1. Kerry / Aug 12 2011 8:17 am

    thankx dude…:)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: