Wednesday, February 6, 2008

Single Selection Radio Button in a Gridview

Wow, who thought this would be that difficult. There's a GroupName attribute in the asp:RadioButton control yet it doesn't group anything. Why? Because when the GridView is rendered it puts a bunch of other junk (related to parent controls) in the name and id fields.

I found one way to do it here (which uses no AJAX):
Here's the post that told me how to do it.

A far cleaner way to do it is to use the ASP.NET mutually exclusive checkbox. I used the Control Toolkit for ASP.NET 2.0 (the older version).

Here's the sample and here's the download

By the way, if you're new to ASP.NET AJAX make sure you include the web.config info from the sample project into your own code. And also make sure you've installed the ASP.NET AJAX Extensions.

No comments: