Click here to Skip to main content
15,891,253 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'
XML
<asp:GridView ID="GridView2" runat="server" ShowHeader="False" AutoGenerateColumns="False"
                   onrowcommand="GridView2_RowCommand"  Width="100%" CellPadding="4"
                   ForeColor="#333333" GridLines="None">

                   <AlternatingRowStyle BackColor="White" />
                   <Columns>
                     <asp:TemplateField>


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

code behind
C#
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
Posted
Updated 17-May-12 1:27am
v2

Try setting the AutoPostback[^] to true.
 
Share this answer
 
hi ,
you need to add the GroupName to the radio button like this:
ASP.NET
<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
 
Comments
Nilesh Rokade 17-May-12 8:02am    
not working ....can u edit code given...
Hi,

You need to set AutoPostBack Property of RadioButton to True.
 
Share this answer
 
Comments
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