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

How to check 'check-box' within a Grid

3 Answers 145 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Svetlana
Top achievements
Rank 1
Svetlana asked on 14 Jul 2010, 02:54 PM
Hello

I have RadGrid control with check-box within a cell:
<td align="center" style="width: 30px;">
    <span title="Test Title"
        id="ctl00_MC_gridSchedule_ctl00_ctl08_HasAccessExtended">
        <input type="image" style="height: 13px; width: 13px; border-width: 0px;" src="/std/WebResource.axd
            checked="Blank" id="ctl00_MC_gridSchedule_ctl00_ctl08_HasAccessExtended_checkBox"
            name="ctl00$MC$gridSchedule$ctl00$ctl08$HasAccessExtended$checkBox">
            <input type="hidden"
                value="Blank" id="ctl00_MC_gridSchedule_ctl00_ctl08_HasAccessExtended_hidden"
                name="ctl00$MC$gridSchedule$ctl00$ctl08$HasAccessExtended$hidden">
   </span>
</td>
I've located the target cell in  the grid : GridDataCell targetCell
How can I check the check-box with id="ctl00_MC_gridSchedule_ctl00_ctl08_HasAccessExtended_checkBox"?

Regards,
Svetlana

3 Answers, 1 is accepted

Sort by
0
Cody
Telerik team
answered on 14 Jul 2010, 05:22 PM
Hello Svetlana,

Using two lines of code you can do this:

HtmlInputCheckBox cbox = targetCell.Find.ById<HtmlInputCheckBox>("ctl00_MC_gridSchedule_ctl00_ctl08_HasAccessExtended_checkBox");
cbox.Check(true, true);

The first parameter of the .Check call indicates whether to check or uncheck the checkbox. true = check the checbox. false = uncheck the checkbox.

The second parameter indicates whether or not to invoke the OnClickChanged event handler for the checkbox. This is useful for AJAX postbacks when a click on the checkbox is supposed to trigger a postback event. If you don't need to trigger a postback, you can set the second parameter to false which will make the test a little more efficient (it won't have to activate some JavaScript in the background).

You could also combine the two lines of code into one like this:

targetCell.Find.ById<HtmlInputCheckBox>("ctl00_MC_gridSchedule_ctl00_ctl08_HasAccessExtended_checkBox").Check(true, true);


Kind regards,
Cody
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
0
Svetlana
Top achievements
Rank 1
answered on 15 Jul 2010, 01:17 PM
Hello Cody,

Thank you for the answer, but the solution does not work :(
Error occurs on
cbox.Check(true, true);

InnerException:
System.NullReferenceException: Object reference not set to an instance of an object.

Seems that the tool does not recognize that the control is check-box. Because

var cbox = targetCell.Find.ByAttributes("name=ctl00$MC$gridSchedule$ctl00$ctl08$HasAccessExtended$checkBox");
cbox.Focus();

wotks fine, but I don't now how to perform "check" action...

Regards,
Svetlana




0
Cody
Telerik team
answered on 15 Jul 2010, 06:08 PM
Hello Svetlana,

It appears you're using VB.NET (my sample was C# code). Instead of using a var, could you try casting it to a HtmlInputCheckBox type with code like this:

Dim cbox As HtmlInputCheckBox = targetCell.Find.ByAttributes(Of HtmlInputCheckBox)("name=ctl00$MC$gridSchedule$ctl00$ctl08$HasAccessExtended$checkBox");

The problem I suspect you're running into is that the plain targetCell.Find.ByAttributes returns a simple "Element" object instead of a HtmlInputCheckBox object. As a result your "var cbox" is a plain Element which can't handle the .Check(true,true) method call.

Regards,
Cody
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
Svetlana
Top achievements
Rank 1
Answers by
Cody
Telerik team
Svetlana
Top achievements
Rank 1
Share this question
or