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

[Solved] Selectable Rows

5 Answers 176 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Apostol Apostolov
Top achievements
Rank 1
Apostol Apostolov asked on 24 Sep 2009, 05:28 PM
Hello,

I am using Grid for my application and I was wondering if there is some way for the rows of the grid to be made (and un-made) selectable, not for the whole grid but for every row for himself. Like if some condition is met - the row is selectable, if it's not met - it's not selectable.
I would greatly aprishiate your help!

Apostol

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 25 Sep 2009, 04:18 AM
Hello Apostol,

Attach OnRowSelecting event to RadGrid, so that you can cancel row selection based on condition using eventArgs.set_cancel(true)  method. Access the griddataItem in event and get the corresponding value in row for checking the condition, then cancel the event accordingly.

-Shinu.
0
Apostol Apostolov
Top achievements
Rank 1
answered on 25 Sep 2009, 08:57 AM
Hello Shinu,

Thanks for the relpy. I'm not very familiar with Javascript - I've read a few articles but i couldn't figure out how to acess the GridDataItem. Every row in my Grid has a checkbox which is the condition - if the checkbox is checked - the row can be selected and if the checkbox is not checked the row cannot be selected. I have t o use something like FindControl() function of GridDataItem to access the checkbox but i couldn't figure out how to do the whole thing through javascript.

Apostol

0
Accepted
Mira
Telerik team
answered on 26 Sep 2009, 12:59 PM
Hi Apostol,

I recommend that you use the OnRowSelecting event handler to achieve the desired by you functionality. Your javascript code should look like:
            function RowSelecting(sender, eventArgs) 
            { 
                var checkBox = args.get_item().findControl("CheckBox1"); 
                if (!checkBox.checked
                    eventArgs.set_cancel(true); 
            } 

Kind regards,
Mira
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Martin
Top achievements
Rank 1
answered on 23 Nov 2009, 07:57 PM
            function RowSelecting(sender, eventArgs) 
            { 
                var checkBox = args.get_item().findControl("CheckBox1"); 
                if (!checkBox.checked
                    eventArgs.set_cancel(true); 
            } 

The above does not work for me. When I reference eventArgs get_item() is not available to me.
I get

eventArgs.get_item()

 

Object doesn't support this property or method

How could I get this resolved as I need to reference controls inside that row.
Thanks

0
Shinu
Top achievements
Rank 2
answered on 24 Nov 2009, 04:59 AM
Hi Martin,

Try the following client side code.

JavaScript:
 
<script type="text/javascript"
    function OnRowSelecting(sender, args) 
    {     
        var checkBox = args.get_gridDataItem().findControl("CheckBox1");  
        if (!checkBox.checked)  
            eventArgs.set_cancel(true);  
    } 
    function OnRowCreated() 
    { 
 
    } 
</script> 
[Note: Also attach OnRowCreated event to grid. get_gridDataItem() is not directly available on the client unless OnRowCreating/OnRowCreated events are hooked up.]

-Shinu.
Tags
Grid
Asked by
Apostol Apostolov
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Apostol Apostolov
Top achievements
Rank 1
Mira
Telerik team
Martin
Top achievements
Rank 1
Share this question
or