Preserving changes to header text

3 posts, 1 answers
  1. Derek
    Derek avatar
    119 posts
    Member since:
    Oct 2008

    Posted 04 Dec 2010 Link to this post

    We have a Radgrid where the header text is modified; this is done on the grid ItemDataBound event. This works properly on the initial page display.

    However, after a postback the header text reverts to the original values. For example; if we use the Editmode=Popup option, teh values that are shown in the popup are the original header text values, not the modified values.

    Here's where the modification is done;

    Protected Sub RadGridInvoiceSubcontracts_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGridInvoiceSubcontracts.ItemDataBound
           If TypeOf (e.Item) Is GridHeaderItem Then
               Using taArea As New InvoiceAreasTableAdapters.AreasTableAdapter
                   Using tArea As InvoiceAreas.AreasDataTable = taArea.GetData
                       For Each rArea As InvoiceAreas.AreasRow In tArea
                           Dim header As GridHeaderItem = DirectCast(e.Item, GridHeaderItem)
                           header("Area" & rArea.AreaID).Text = rArea.AreaName
                           header.EnableViewState = True
                   End Using
               End Using
           End If
       End Sub
  2. Answer
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 05 Dec 2010 Link to this post

    Hello Derek,

    Give a try with the following approach to change the header text.

        <telerik:GridBoundColumn DataField="EmployeeID" HeaderText="EmployeeID" UniqueName="EmployeeID">

    Protected Sub RadGrid1_PreRender(sender As Object, e As EventArgs)
        TryCast(RadGrid1.MasterTableView.GetColumn("EmployeeID"), GridBoundColumn).HeaderText = "new header"
    End Sub

  3. Derek
    Derek avatar
    119 posts
    Member since:
    Oct 2008

    Posted 06 Dec 2010 Link to this post

    That worked perfectly, thanks!

    We wrapped our looping code around the trycast statement, and the values are changed AND preserved through postbacks.
Back to Top