How do I unselect and select a radio button on different rows of a GridView?

Posted on 2009-12-31
Last Modified: 2012-05-08
I have two gridviews on a page.  Each grid has a list of things that are potential matches.  The users has to pick one item from each grid and then click a "Reconcile" button.

How can I, through JQuery, make sure that only one row in each grid is selected?  Specifically I need code to execute on the onclick of a radiobutton (not in a radiobuttonlist because the buttons are spread across rows of the gridview) to unselect all the radio buttons in that grid and then select just the button from which the onclick fired.

This is how the gridview columns are setup:


                        <asp:HyperLinkField DataTextField="ExtractID" 


                            DataNavigateUrlFields="ExtractID" HeaderText="ID" SortExpression="ExtractID" 

                           ItemStyle-BorderColor="#CCCCCC"  />

                        <asp:BoundField DataField="JobName" HeaderText="Job Name"  /> 

                       <asp:BoundField DataField="FileName" HeaderText="File Name" />

                       <asp:BoundField DataField="DeliveryProtocolName" HeaderText = "Delivery Protocol" />

                       <asp:BoundField  DataField="FrequencyName" HeaderText="Frequency" />           

                       <asp:TemplateField HeaderText="Description" >

                        <ItemStyle HorizontalAlign="Left" Width="150" Font-Size="X-Small" />


                                    <asp:Label ID="lblDesc"  style=" "  Text='' runat="server"/>                    





                                <asp:RadioButton ID="rbUserExtractToReconcile" runat="server" />




Open in new window

Question by:Bruce
    LVL 81

    Expert Comment

    Hello cylikon,

    You need to group radio button by give them the same groupname attribute :

    Other link :
    (section To group individual RadioButton Web server controls)

    <asp:RadioButton ID="rbUserExtractToReconcile" GroupName="gnUserExtractToReconcile" runat="server" />

    Open in new window

    LVL 1

    Author Comment

    leakim971:  Thanks for the response.  

    I tried you suggestion but it doesn't seem to work.  I think its because the name is mangled by the ASP.NET engine.  When I look at the source of the HTML page all the "name"'s of the radio buttons are different.


    On that, I did try to add the names manually in the RowDataBound Event but they still got mangled.  See my code below.

    Any other ideas?  Thoughts?

    protected void gvUserEnteredExtracts_RowDataBound(object sender, GridViewRowEventArgs e )
            GridViewRow row = e.Row;
            if (row.RowType == DataControlRowType.DataRow)
                RadioButton rb = (RadioButton) row.FindControl("rbUserExtractToReconcile");
                rb.Attributes.Add("name", "gnUserExtractToReconcile");

    Open in new window

    LVL 81

    Accepted Solution

    LVL 81

    Expert Comment

    Thanks for the points!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Suggested Solutions

    Title # Comments Views Activity
    network + 7 57
    javascript question 6 21
    Convert a Master Page to HTML 16 32
    How to parametrize bing map on webbrowser control 6 34
    PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
    JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now