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

[Solved] Accessing rows and template column

3 Answers 122 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bogice
Top achievements
Rank 1
Bogice asked on 11 Dec 2009, 08:40 PM

Hi Telerik,

I have a collection which binds to a grid. In the ItemDataBound event I’d like to access the obj which ties to the current row. How can I do that.

Secondly, I am using template Column, how should I access the control in that column

Thank you  

3 Answers, 1 is accepted

Sort by
0
Accepted
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 12 Dec 2009, 03:30 AM
// This runs for each row in your grid
protected void RadGrid1_ItemDataBound(Object sender, Telerik.WebControls.GridItemEventArgs e) 
        if (e.Item is GridDataItem) //Make sure we're dealing with a data item
       { 
           GridDataItem dataRow = e.Item as GridDataItem; 
            if (dataRow["Country"].Text = "Mexico") //"Country" is the unique column name, and Text is it's value
           { 
               dataRow.CssClass = "MyMexicoRowClass"
           }
          
           TextBox president = (TextBox)dataRow["Presidents"].FindControl("presNameTextBox"); //This finds the controls in your template column names "Presidents"
       } 

I changed this example slightly
http://www.telerik.com/help/aspnet/grid/grdconditionalformatting.html

:)










0
Bogice
Top achievements
Rank 1
answered on 12 Dec 2009, 09:39 AM
Thank you Steve,
the (e.Item is GridDataItem) is exactly pinpoint the problem since i have error when running. It's appear that ItemDataBound is triggered for header, pager... also. and FindControl in that moment return null.  Hope that helps others.
Anh
 
0
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 12 Dec 2009, 09:04 PM
No problem, would you mind clicking mark as answer at the bottom of my post perhaps? :)
Tags
Grid
Asked by
Bogice
Top achievements
Rank 1
Answers by
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
Bogice
Top achievements
Rank 1
Share this question
or