?
Solved

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

Posted on 2009-12-31
4
Medium Priority
?
823 Views
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.

Thanks!
This is how the gridview columns are setup:

  <Columns>                        
                        <asp:HyperLinkField DataTextField="ExtractID" 
                            DataNavigateUrlFormatString="~/WebForms/Extract/ExtractList.aspx?extractID={0}"
                            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" />
                            <ItemTemplate>                    
                                    <asp:Label ID="lblDesc"  style=" "  Text='' runat="server"/>                    
                            </ItemTemplate>                                
                       </asp:TemplateField>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:RadioButton ID="rbUserExtractToReconcile" runat="server" />
                            </ItemTemplate>
                        </asp:TemplateField> 
                    </Columns>

Open in new window

Extract-Reconciliation-no-menu.png
0
Comment
Question by:Bruce
  • 3
4 Comments
 
LVL 83

Expert Comment

by:leakim971
ID: 26154299
Hello cylikon,

You need to group radio button by give them the same groupname attribute : http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.radiobutton.groupname(VS.100).aspx

Other link : http://msdn.microsoft.com/en-us/library/z26z1156(VS.100).aspx
(section To group individual RadioButton Web server controls)


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

Open in new window

0
 
LVL 1

Author Comment

by:Bruce
ID: 26154952
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.

name="ctl00$ContentPlaceHolder1$gvUserEnteredExtracts$ctl02$gnUserEnteredExtracts"
name="ctl00$ContentPlaceHolder1$gvUserEnteredExtracts$ctl03$gnUserEnteredExtracts"

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

0
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 26155005
0
 
LVL 83

Expert Comment

by:leakim971
ID: 26155717
Thanks for the points!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…
Suggested Courses
Course of the Month15 days, 20 hours left to enroll

850 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