This is a migrated thread and some comments may be shown as answers.

Checking radio buttons with the same name.

2 Answers 110 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
SD
Top achievements
Rank 1
SD asked on 02 Jun 2010, 07:01 AM
Hi Guys,

I've got a situation in which I have 6 radio buttons arranged in pairs and each pair has an identical name.
In each pair, one radio button is a 'No' and the other 'Yes'. Only 'Yes' or 'No' can be checked in any give time. 

Running the following didn't help as I'm missing something to help distinguishing between the Yes and No radios in each pair...

    var radios = Find.AllControls<HtmlInputRadioButton>();
                foreach (HtmlInputRadioButton rb in radios)
                {
                    rb.Check(true, true);
                }

<tbody> 
<tr> 
<td> 
<label> 
<input type="radio" value="true" name="assessmentForm:generalVerified"/> 
Yes 
</label> 
</td> 
<td> 
<label> 
<input type="radio" value="false" name="assessmentForm:generalVerified"/> 
No 
</label> 
</td> 
</tr> 
</tbody> 

Ta,
SD.

2 Answers, 1 is accepted

Sort by
0
SD
Top achievements
Rank 1
answered on 03 Jun 2010, 04:01 AM
Ok, problem solved....

IList<HtmlInputRadioButton> rd = (from b in Find.AllControls<HtmlInputRadioButton>()  
where b.Value.Contains("true") select b).ToArray(); 
 
rd.ElementAt(1).Check(truetrue); 

So if you want to mark the 'No' radio control on the 2nd pair from the top, all you do is changing 'true' to 'false' in the LINQ query and
address the 2nd element in the array as I'm doing (ElementAt(1)).
0
Missing User
answered on 04 Jun 2010, 10:20 PM
Hello SD,

I'm glad you got this scenario working. You can also try the following:

HtmlInputRadioButton yes = ActiveBrowser.Find.ByExpression<HtmlInputRadioButton>("TextContent=yes","|","name=assessmentForm:generalVerified");
HtmlInputRadioButton no = ActiveBrowser.Find.ByExpression<HtmlInputRadioButton>("TextContent=no", "|", "name=assessmentForm:generalVerified");

It's using a Find Expression to first find the label by content, then ("|") find the radio button child. Please see this documentation on find expressions for reference.

All the best,
Nelson Sin
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
General Discussions
Asked by
SD
Top achievements
Rank 1
Answers by
SD
Top achievements
Rank 1
Missing User
Share this question
or