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

How to access a div that is inside a RadGrid

4 Answers 738 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stavros
Top achievements
Rank 1
Stavros asked on 26 Jun 2009, 11:47 AM
I have a div with its own id in the ItemTemplate of a GridTemplateColumn of a RadGrid.
 How can I access this div from the code behind?
If it was a div in the web page I could access it just by typing its id but this method does not work now that it is nested inside the grid.
Thank you very much.

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Jun 2009, 12:03 PM
Hello Stavros,

Here is an example of how to access a div inside the TemplateColumn of a Grid:
aspx:
 <telerik:GridTemplateColumn> 
      <ItemTemplate> 
            <div id="divlayer" runat="server"
              Hello             
            </div> 
       </ItemTemplate> 
  </telerik:GridTemplateColumn> 

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            HtmlGenericControl container = (HtmlGenericControl)item.FindControl("divlayer"); 
        } 
    } 

Thanks
Princy.
0
Stavros
Top achievements
Rank 1
answered on 26 Jun 2009, 12:28 PM
Thnx a lot but I want to access this div tag(or a panel tag that renders to a div tag) in a

 

protected void Page_LoadComplete(object sender, EventArgs e)

 



method of a page.
How can I do that?
Thank you very much for helping me on this.
0
Stavros
Top achievements
Rank 1
answered on 26 Jun 2009, 12:43 PM
To be more specific have entered two divs in the Item template and I want to make the visible/invisible by checking some other variables that I pass to my page.
Do you believe that this is possible?
Thank you again.
0
Sebastian
Telerik team
answered on 01 Jul 2009, 12:57 PM
Hello Stavros,

The proper place to change the visibility of controls which reside in grid rows is the ItemCreated server handler of the grid. There you can find the control in question by its id using the e.Item.FindControl(controlId) method.

Further information about the ItemCreated/ItemDataBound events of RadGrid and the lifecycle of the control you can find in these articles:

http://www.telerik.com/help/aspnet-ajax/grddistinguishdifferencesbetweenitemcreateditemdatabound.html
http://www.telerik.com/help/aspnet-ajax/grdeventsequence.html

Greetings,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Stavros
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Stavros
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or