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

Getting the Unique Column Name OnRowCreated

3 Answers 200 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ace
Top achievements
Rank 1
Ace asked on 20 Apr 2010, 05:16 PM
Hello

I have an OnRowCreated event in my RadGrid.  I need to add a onclick event depending on what column it is for each cell.  Instead of using (i == #) in my loop to determine the onclick event (because the column index numbers change depending on the data being loaded), I would like to find out the column unique name (elementName in the code below) for that cell and use that as the determinant for the onclick event.  But so far, I have not found out how to obtain the unique name for the column. 

Thanks
Oscar

            function RowCreated(sender, eventArgs) {  
                var dataItem = eventArgs.get_gridDataItem();  
 
                for (var i = 0; i < dataItem.get_element().cells.length; i++) {  
                                          
                    //if (elementName == 'CompName') {  
                    if (i == 1) {  
                        dataItem.get_element().cells[i].onclick = function() {  
                            this.selected = this.selected == true ? false : true;  
                            //some function  
                        };  
                    }  
                    else if (i == 2) {  
                        dataItem.get_element().cells[i].onclick = function() {  
                            this.selected = this.selected == true ? false : true;  
                            //some function  
                        };  
                    }  
                    else if (i == 3) {  
                        dataItem.get_element().cells[i].onclick = function() {  
                            this.selected = this.selected == true ? false : true;  
                            //some function  
                        };  
                    }                         
                }  
            }  
 

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 21 Apr 2010, 06:35 AM
Hello Ace,

Try using get_cell() method to get the particular cell based on given ColumnUniqeuName.

function RowCreated(sender, eventArgs) { 
 eventArgs.get_gridDataItem().get_cell("CompName").onclick = function() { 
//some function 

Regards,
Princy


0
Ace
Top achievements
Rank 1
answered on 21 Apr 2010, 10:03 PM
I tried it and got the following javascript error:

Message: 'get_cell(...)' is null or not an object

<telerik:GridTemplateColumn UniqueName="CompName" HeaderText="Company Name" SortExpression="CompName" HeaderStyle-Width="50%">  
<ItemTemplate><b><%#Eval("CompName")%></b>&nbsp;&nbsp;(<%#Eval("CompanyID")%>)<br /><small><%#Eval("CompLocation")%></small></ItemTemplate>  
<ItemStyle Wrap="false" />  
</telerik:GridTemplateColumn> 

This is the column CompName in my RadGrid.
0
Princy
Top achievements
Rank 2
answered on 27 Apr 2010, 08:03 AM
Hello Ace,

The get_cell() client side method is added for GridDataItem in the version Q2 2008 (version 2008.2.723) RadControls for ASP.NET AJAX. Probably the problem happens if you are using older version than this. Could you try download the latest version of RadControls and see whether it is working fine for you?
Updating RadControls for ASP.NET to another version or license

Regards,
Princy.
Tags
Grid
Asked by
Ace
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ace
Top achievements
Rank 1
Share this question
or