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

Preserving changes to header text

2 Answers 60 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Derek
Top achievements
Rank 1
Derek asked on 04 Dec 2010, 03:23 PM
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
                   Next
               End Using
           End Using
       End If
   End Sub

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 06 Dec 2010, 05:18 AM
Hello Derek,

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

ASPX:
<Columns>
    <telerik:GridBoundColumn DataField="EmployeeID" HeaderText="EmployeeID" UniqueName="EmployeeID">
    </telerik:GridBoundColumn>
</Columns>

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

Thanks,
Princy.
0
Derek
Top achievements
Rank 1
answered on 06 Dec 2010, 01:10 PM
That worked perfectly, thanks!

We wrapped our looping code around the trycast statement, and the values are changed AND preserved through postbacks.
Tags
Grid
Asked by
Derek
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Derek
Top achievements
Rank 1
Share this question
or