Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid Column Header Text...

Status
Not open for further replies.

steverbs

Programmer
Jul 17, 2003
253
GB
Hi all.

I thought this would have been a very simple task, but it has become a bit of a nightmare. How do I dynamically change the header text of a DataGrid column at runtime? I have the following code
Code:
If (objShop.deliveryCalculationMode = Entities.Shop.deliveryCalculationModeType.orderPrice) Then
    Me.dgDeliveryBands.Columns(0).HeaderText = "Max Order Value"
ElseIf (objShop.deliveryCalculationMode = Entities.Shop.deliveryCalculationModeType.orderWeight) Then
    Me.dgDeliveryBands.Columns(0).HeaderText = "Max Weight"
End If
But it doesn't do anything. I have tried putting this in Form_Load, DataGrid_PreRender, etc but it doesn't work.

Any ideas?

Stephen.
 
Why don't you try it when the item is created? e.g.
Code:
    Private Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemCreated
        Select Case e.Item.ItemType

            Case ListItemType.Header
                If (objShop.deliveryCalculationMode = Entities.Shop.deliveryCalculationModeType.orderPrice) Then
                    e.Item.Cells(0).Text = "Max Order Value"
                ElseIf (objShop.deliveryCalculationMode = Entities.Shop.deliveryCalculationModeType.orderWeight) Then
                    e.Item.Cells(0).Text = "Max Weight"
                End If

        End Select
    End Sub

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Of course. Cheers, ca8msm. I'll give it a try.
 
Yeah. That worked a treat.

Thanks again.

Stephen.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top