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

[Solved] Using $Find with Dynamically Created Grid

2 Answers 112 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul Mc
Top achievements
Rank 1
Paul Mc asked on 12 Oct 2009, 09:40 AM
Hi

I dont know if it is possible, but we are trying to use the Ajax $Find method to find a RadGrid that has been created in the code behind.  Below is how we create the Rad Grid:

Protected WithEvents grdTypes As New RadGrid  
 
Protected Sub Page_Init(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Init  
 
    With grdTypes  
          .ID = "grdTypes" 
          .AllowSorting = True 
          .DataSourceID = "SqlDataSource" 
          .AllowAutomaticDeletes = True 
          .AllowAutomaticInserts = True 
          .AllowAutomaticUpdates = True 
          .ClientSettings.ClientEvents.OnRowSelected = "SelectRow()"
          'ETC  
 
    End With 
 
End Sub 

Following the example in the demos for detecting a row selection, we then have the following code in javascript:

<script language="javascript" type="text/javascript">  
     
    function SelectRow(sender, eventArgs) {  
        var grid = $find("<%=grdTypes.ClientID %>");  
    }  
 
</script> 

Everything appears to be hooked up correctly, and the grid's Client ID is being translated to the correct name (i.e. ctl00_ContentPlaceHolder1_grdTypes), however the "grid" variable always appears to be NULL which means that we are unable to check the selected items count.

Any help would be very welcome.

Paul






2 Answers, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 14 Oct 2009, 10:44 AM
Hi Paul,

I recommend that you set the OnRowSelected event handler in the following way:
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init 
  
    With grdTypes 
          .ID = "grdTypes"
          .AllowSorting = True
          .DataSourceID = "SqlDataSource"
          .AllowAutomaticDeletes = True
          .AllowAutomaticInserts = True
          .AllowAutomaticUpdates = True
          string js = "function SelectRow(sender, eventArgs) { 
            var grid = $find(\"<%=" + grdTypes.ClientID +  "%>\"); 
                } ";
          .ClientSettings.ClientEvents.OnRowSelected = js
          'ETC 
  
    End With
  
End Sub

Please try this and tell me whether it works for you.

All the best,
Mira
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Paul Mc
Top achievements
Rank 1
answered on 15 Oct 2009, 09:56 AM
Mira

Thanks for coming back to me.

When I first got your reply, I was a little lost as to what I had done on the basis that nothing seemed to be working at all.  When I came to write this reply, after getting it mysteriously working, I realised what I had done.  Upon defining the procedure for OnRowSelected in the code behind, I have added brackets to the statement:

.ClientSettings.ClientEvents.OnRowSelected = "SelectRow()"

This seems to cause the grid variable in the js to be set with Null when you do $Find.

All sorted now and sorry for wasting your time.
Tags
Grid
Asked by
Paul Mc
Top achievements
Rank 1
Answers by
Mira
Telerik team
Paul Mc
Top achievements
Rank 1
Share this question
or