Friday, September 26, 2014

Access RadGrid on Client using Javascript/Jquery

To access RadGrid on client, use following code.
I will also show the code that doesn't work:

 
// didnt work. .Net crash saying The Controls collection cannot be modified because the control contains code blocks (i.e. <%--<% %>--%>)
<%--var grid1 = $find("<%= RadGrid1.ClientID%>");--%>

//didnt work. This just gives Null.   
<%--var grid1 = $find("<%# RadGrid1.ClientID%>"); --%> 

//didnt work. This just gives Null.  
<%--var grid1 = document.getElementById('<%# RadGrid1.ClientID%>') --%> 

//didnt work. It give me ID of RadGrid; not a reference to object.  
var grid1 = document.getElementById('RadGrid1').id;  

//This gives reference as htmldiv control which still cant be used to access functions of radgrid.  
var grid1 = document.getElementById('RadGrid1')

  
// THIS WORKS **********************************************
  
var grid = $find(document.getElementById("RadGrid1").id);

var masterTable = grid.get_masterTableView();
  
//********************************************
  

3 comments:

Anonymous said...

THANKS! You don't know how long I struggled with this! John

Saqib Mahmood said...

You Welcome!

Anonymous said...

After spending few hours finally solution for my problem!