Changing HeaderText in runtime..

8 posts, 0 answers
  1. Milan Gurung
    Milan Gurung avatar
    74 posts
    Member since:
    Aug 2008

    Posted 07 Oct 2008 Link to this post

    Hi,

    How can I change the headerText for a grid in Runtime?

    Thanks.
    Milan G
  2. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 07 Oct 2008 Link to this post

    Hello Milan,

    Test the following code-snippet:
        Protected Sub Button1_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles Button1.Click 
            RadGrid1.MasterTableView.GetColumn("ID").HeaderText = "NEW TEXT" 
            RadGrid1.Rebind() 
        End Sub 

    Regards,
    Daniel
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 07 Oct 2008 Link to this post

    Hi,

    You can also change the heder text in the ItemDataBound event as shown below.
    cs:
     protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridHeaderItem) 
            { 
                GridHeaderItem headerItem = (GridHeaderItem)e.Item; 
                headerItem["Template"].Text = "CustomText"
            } 
        } 

    Princy.
  5. John Billiris (JSBBS)
    John Billiris (JSBBS) avatar
    27 posts
    Member since:
    Mar 2007

    Posted 09 Aug 2009 Link to this post

    Is there any reason why changing the HeaderText can't be done during the page's / user-control's OnPreRender event handler?
  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 10 Aug 2009 Link to this post

    Hello John,

    The Radgrid is rendered only after the page's PreRender event. So the grid or its elements wont be available in the page's/ usercontrol's PreRender event. Hope this answers your question.

    Thanks
    Princy.
  7. John Billiris (JSBBS)
    John Billiris (JSBBS) avatar
    27 posts
    Member since:
    Mar 2007

    Posted 10 Aug 2009 Link to this post

    Thanks Princy.

    As a note, the grid is available in the OnPreRender event handler, but changing the HeaderText of any column doesn't have any effect on the actual text displayed on screen.

    So, I'm not sure whether Telerik want to pursue this... I'll leave that up to them.

    And in my case, I check the HeaderText in the method that handles the data-binding. It works and I'm happy.
  8. Milan Gurung
    Milan Gurung avatar
    74 posts
    Member since:
    Aug 2008

    Posted 11 Aug 2009 Link to this post

    Hi,

    I got a better solution by changing the column name itself in the dataset before binding it to grid. This is more flexible. I hope this might help.

    Thanks,
    Milan G
  9. tparus
    tparus avatar
    3 posts
    Member since:
    Aug 2008

    Posted 03 Sep 2009 Link to this post

    I am doing this in the ItemCreated event. The weird thing is that it doesn't render the first time. However, when I drag a column up to the Group box, the grid refreshes and the new/correct column names do appear. I hope this helps.

     

    Protected Sub gridSales_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles gridSales.ItemCreated

     

     

        If (TypeOf e.Item Is GridHeaderItem) Then

     

     

            Dim headerItem As GridHeaderItem = CType(e.Item, GridHeaderItem)

     

     


            Dim
    i As Integer = 1

     

     

            Dim colDate As Date

     

     

            For Each column As GridColumn In gridSales.MasterTableView.RenderColumns

     

     

                If (TypeOf column Is GridBoundColumn) Then

     

     

                    ' The UniqueName of my columns are SalesMonth01...SalesMonth12
                    If
    column.UniqueName.Contains("SalesMonth") = True Then

     

                        colDate = DateAdd(DateInterval.Month, -i, Now)

                        column.HeaderText =

    String.Format("{0:MMM-yy}", colDate)

     

                        i += 1

     

                    End If

     

     

                End If

     

     

            Next

     

            headerItem.Dispose()

     

    End If

     

     

    End Sub

     

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017