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

Client Side Grid Access problem

2 Answers 142 Views
Grid
This is a migrated thread and some comments may be shown as answers.
david
Top achievements
Rank 1
david asked on 24 Sep 2008, 01:21 PM
I use client side grid variable access quite a bit but have one program that I cant seem to find the problem with and was hoping someone would indulge me on a quick review.  On the 'getCellByColumnUniqueName' function I get the JS error:

error:'undefined' is null or not an object.

in the codebehind: 

GridDataItem gridDataItem = e.Item as GridDataItem;
HyperLink GradeBook = e.Item.FindControl("GradeBook") as HyperLink;
GradeBook.Attributes[
"href"] = "#";
GradeBook.Attributes[
"onclick"] = string.Format("return ShowGradeBook('{0}');", e.Item.ItemIndex);

which works fine, my JS Function runs:

function ShowGradeBook(rowIndex)

{

var mtv = $find("<%= RadGrid1.ClientID %>").get_masterTableView();

mtv.selectItem(mtv.get_dataItems()[rowIndex].get_element());

var selectedRows = mtv.get_selectedItems();

var row = selectedRows[0];

 alert(

"InGradeBOok=" + rowIndex);

 tf = mtv.getCellByColumnUniqueName(row,

"CourseID")

var CourseID = tf.innerHTML;

CourseID is defined in the grid as:

<telerik:GridBoundColumn DataField="CourseID" UniqueName="CourseID" Display="false" ></telerik:GridBoundColumn>

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 25 Sep 2008, 05:18 AM
Hi David,

Try accessing the cell value for the desired column on the client side as shown below.

JS:
function ShowGradeBook(rowIndex) 
       { 
        var mtv = $find("<%= RadGrid1.ClientID %>").get_masterTableView(); 
         mtv.selectItem(mtv.get_dataItems()[rowIndex].get_element()); 
         var selectedRows = mtv.get_selectedItems(); 
         alert("InGradeBOok=" + rowIndex) 
         
         var row = mtv.get_dataItems()[rowIndex]; 
         var cell = mtv.getCellByColumnUniqueName(row, "CourseID");  
         alert( cell.innerHTML) 
       } 


Regards
Shinu.
0
david
Top achievements
Rank 1
answered on 01 Oct 2008, 05:42 PM
That worked thank you.

Curious though, this aspx has three grids, two of them work using this code:

var mtv = $find("<%= RadGrid2.ClientID %>").get_masterTableView();

mtv.selectItem(mtv.get_dataItems()[rowIndex].get_element());

var selectedRows = mtv.get_selectedItems();

var row = selectedRows[0];



BUT the 3rd one does not and had to use the suggested approach:

var mtv = $find("<%= RadGrid3.ClientID %>").get_masterTableView();

mtv.selectItem(mtv.get_dataItems()[rowIndex].get_element());

var selectedRows = mtv.get_selectedItems();

var row = mtv.get_dataItems()[rowIndex];

I'm obviously not understanding something about the Grid / or API, can anyone explain the reason for the difference?


thanks

Tags
Grid
Asked by
david
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
david
Top achievements
Rank 1
Share this question
or