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

Cell click event

1 Answer 85 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 31 Oct 2008, 05:08 PM
Have looked on here and there is a fair few posts regarding this issue but they are quite dated and have a lot of different answers. I am wanting to be able to click on a cell in a grid and get not only the value but also a way to know what column and row that cell belongs to.
Any help is greatly appreciated, cheers.
Paul

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Nov 2008, 08:53 AM
Hi Paul,

You can try out the following code to get the cell text, column UniqueName and row index on the cell click event in a grid.
cs:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
   { 
      foreach (GridDataItem dataItem in RadGrid1.Items) 
       { 
        foreach(GridColumn col in RadGrid1.Columns) 
          { 
                  string cellText = dataItem[col.UniqueName].Text; 
                  int rowIndex = dataItem.ItemIndex;  
                  string columnUniqueName = col.UniqueName.ToString(); 
                  dataItem[col.UniqueName].Attributes.Add("OnClick", "return Click('" + celltxt + "','" + rowIndex + "','" + columnUniqueName + "');"); 
          }                 
      } 
  } 

js:
 function Click(key,key1,key2) 
 { 
  alert("cell text=" +key + "; row index =" +key1 + ";column UniqueName =" +key2) 
   
 } 

Thanks
Princy.
Tags
Grid
Asked by
Paul
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or