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

Access grid template controls in DataBound

2 Answers 105 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Radoslaw
Top achievements
Rank 1
Radoslaw asked on 24 May 2010, 08:26 AM
Hi!

Can I access controls in grid template column after data bound (in RadGrid.DataBound)?
I need to hide one control inside the column and i dont want to do this for every row. Is it possible?

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 24 May 2010, 08:57 AM
Hello Radoslaw,

Yes, It is possible to access the controls in DataBound event. You need to loop through the items using the following code and use the FindControl() method to access the control.

C#:
protected void RadGrid1_DataBound(object sender, EventArgs e) 
    { 
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items) 
        { 
            Label lb = (Label)item.FindControl("lblUsername"); 
            string v = lb.Text; 
        } 
    } 

A better approach would be using the ItemDataBound event than DataBound. Check the following demo for more information on this.
Accessing Cells and Rows

Regards,
Shinu.
0
Radoslaw
Top achievements
Rank 1
answered on 24 May 2010, 09:05 AM
It is not was is perfect but is acceptable.
The reason i want to do this after data bind is beasuse i need to do some heavy work. I want to do this once and then apply result to the grid.
Thanks.
Tags
Grid
Asked by
Radoslaw
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Radoslaw
Top achievements
Rank 1
Share this question
or