954,580 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Select only one radio button in Gridview

Hi,

I am using below code to check only one radio button which is in gridview item template. But it allow multiple selection as CheckBoxes.

My code:

<columns>
<asp:TemplateField HeaderText="Select">
                                <ItemTemplate >
                                    <asp:RadioButton ID="rd1" GroupName="rdBox"  runat="server"  />
                                </ItemTemplate>
                               </asp:TemplateField>
</columns>


Please help me.

Thanks !

Pankaj Singh

Pankaj18
Light Poster
38 posts since Jul 2009
Reputation Points: 9
Solved Threads: 0
 

You question is not clear. Please be precise.

To check multiple check boxes you must have it at first. But i don't see it in your code. If you try to check multiple check boxes with the same GroupName from codebehind it will allow you to do so but if user tries to select multiple checkboxes with the same group name in the web page it will just not happen.

nccsbim071
Junior Poster
130 posts since Jul 2009
Reputation Points: 35
Solved Threads: 6
 

Try this. The code is tested.


*************************************************************


protected void rbtnSelect_CheckedChanged(object sender, EventArgs e)
{
RadioButton selectButton = (RadioButton)sender;
GridViewRow row = (GridViewRow)selectButton.Parent.Parent;
int a = row.RowIndex;
foreach (GridViewRow rw in gvwMixes.Rows)
{
if (selectButton.Checked)
{
if (rw.RowIndex != a)
{
RadioButton rd = rw.FindControl("rbtnSelect") as RadioButton;
rd.Checked = false;
}
}
}
}

innu13
Newbie Poster
1 post since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

First give the groupname to radio button so that All radio buttons in rows would have same group name. I hope this will word, if not, try to do it through javascript, you don't need to write server side code if you are not applying pagination in your grid.

sufyan2011
Junior Poster
166 posts since Dec 2011
Reputation Points: 9
Solved Threads: 20
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You