2009
09.12

Here’s another one of those classic Gridview problems:

I’ve got a Gridview that needs to have a RadioButtonList in it so that users can select only one row.

You can’t do this in ASP.NET with use of the <asp:RadioButton runat=”server”  />. Even though you can fill in a groupname it doesn’t work.
The reason it doesn’t work is that the rendered radiobuttons all have a different “name” attribute (you know, because the namingcontainer requires that all controls have a unique id).

The solution is very easy though; instead of using the .NET radiobutton control we will use a plain old <input type=”radio” />

Just like this:

<input type=”radio” name=”defaultfilegroup” value=’<%# Eval(“resource”) %>’ />

The name attribute works like the groupname; make it equal for all relevant radiobuttons.
The value attribute will contain the value of what the user selected. This is what we’ll retrieve as the selected option.

Retrieving the selected option:

supposing you save all changes when the user hits the “save” button here’s what we’ll do:

    public void SaveSetupLinkButton_Click(object sender, EventArgs e)
    {
        string selectedFile = Request["defaultfilegroup"];
    }

Whoa! That’s how easy it is.

Like this? Use the share buttons below!

  • Share/Bookmark

No Comment.

Add Your Comment