Access grid template controls in DataBound

3 posts, 1 answers
  1. Radoslaw
    Radoslaw avatar
    40 posts
    Member since:
    Sep 2007

    Posted 24 May 2010 Link to this post

    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. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 24 May 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Radoslaw
    Radoslaw avatar
    40 posts
    Member since:
    Sep 2007

    Posted 24 May 2010 Link to this post

    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.
Back to Top