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

change headerText at runtime

3 Answers 85 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Wai
Top achievements
Rank 1
Wai asked on 05 Sep 2008, 06:53 PM
Hello,

In the header, I would like to include the number of items in the radGrid
I have something like this after the grid is bound, but the header is not changed.
RadGrid.Columns("col").HeaderText = counter 

Someone in the forum suggested to use Rebind() in PreRender event.  Does anyone know if there are any other ways to change the header?

Thanks,

Wai

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 Sep 2008, 04:28 AM
Hi Wai,

Try the following code snippet to set the HeaderText of a GridColumn to the number of the items in Grid.

CS:
protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        string count = RadGrid1.PageSize.ToString();  
        if (e.Item is GridHeaderItem) 
        { 
            GridHeaderItem header = (GridHeaderItem)e.Item; 
            header["columnUniqueName"].Text = count
        } 
   } 


Thanks
Princy.
0
Wai
Top achievements
Rank 1
answered on 08 Sep 2008, 03:02 PM

Thank you for your reply.

Actually, my counter is set like this:

Private Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs)  
    If TypeOf e.Item Is GridDataItem Then  
        counter += 1  
    End If  
End If 

I wonder if there is a way to change the header after the grid is bound.

Thanks,

Wai
0
Sebastian
Telerik team
answered on 08 Sep 2008, 03:18 PM
Hello Wai,

This can be done intercepting the PreRender event of the grid as shown in the last paragraph of this help topic. Do not forget to rebind the grid explicitly (invoking its Rebind() method) to commit the changes.

Best regards,
Stephen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Wai
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Wai
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or