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

cell text value onclick

1 Answer 28 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Savyo
Top achievements
Rank 1
Savyo asked on 06 Sep 2012, 12:52 PM
I want  to get the cell text value in javascript the oncell click event. How do I get this.
Pls Help
thanks in advance.
Savyo

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 06 Sep 2012, 01:10 PM
Hi,

Try the following code to access the cell value in onclick event.
C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
 if (e.Item is GridDataItem)
 {
  GridDataItem item = (GridDataItem)e.Item;
  foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns)
  {
     GridDataItem dataItem = (GridDataItem)e.Item;
     dataItem[col.UniqueName].Attributes.Add("onclick", "CellClick('" + dataItem.ItemIndex + "','" + col.UniqueName + "');");
  }
 }
}
JS:
function CellClick(index, name) {
    var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
    var row = masterTable.get_dataItems()[index];
    alert(masterTable.getCellByColumnUniqueName(row, name).innerHTML);
    }

Thanks,
Shinu.
Tags
Grid
Asked by
Savyo
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or