Click here to Skip to main content
15,608,553 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all
i used radio buttons in gridview i want only single radio button should be checked so i used following code'
<asp:GridView ID="GridView2" runat="server" ShowHeader="False" AutoGenerateColumns="False"
                   onrowcommand="GridView2_RowCommand"  Width="100%" CellPadding="4"
                   ForeColor="#333333" GridLines="None">

                   <AlternatingRowStyle BackColor="White" />

                   <asp:RadioButton ID="rblselect" runat="server" Enabled="true" RepeatDirection="Horizontal"  Width="5px" OnSelectedIndexChanged="rbSelector_CheckedChanged" />

code behind
protected void rbSelector_CheckedChanged(object sender, System.EventArgs e)
           //Clear the existing selected row
           foreach (GridViewRow oldrow in GridView2.Rows)
               ((RadioButton)oldrow.FindControl("rblselct")).Checked = false;

           //Set the new selected row
           RadioButton rb = (RadioButton)sender;
           GridViewRow row = (GridViewRow)rb.NamingContainer;
           ((RadioButton)row.FindControl("rblselect")).Checked = true;

can any one suggest me where i went wrong event is not firing at all after changing radio button
Updated 17-May-12 1:27am

Try setting the AutoPostback[^] to true.
Share this answer
hi ,
you need to add the GroupName to the radio button like this:
<asp:radiobutton id="rblselect" runat="server" enabled="true" repeatdirection="Horizontal" xmlns:asp="#unknown">
        Width="5px" OnSelectedIndexChanged="rbSelector_CheckedChanged" GroupName="Radio" /></asp:radiobutton>

means it will check only one radio button at the same time
Share this answer
Nilesh Rokade 17-May-12 8:02am    
not working ....can u edit code given...

You need to set AutoPostBack Property of RadioButton to True.
Share this answer
Narasappa From Dharwad 17-May-12 8:14am    
if i set AutoPostBack Property of RadioButton to True. den also its not firing and no one Radio Buttons selected at all ..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900