SortExpression not working in ASP.NET If Header Text is passed dynamically through VB code
For a header cell with sorting enabled, the DataControlField
will add a LinkButton
to the TableCell
, and set its properties accordingly.
When you set the TableCell
's Text
property, it removes all of the controls which were created by the DataControlField
. This includes the LinkButton
used to sort the cell.
You need to change the text of the LinkButton
instead.
Dim text As String
If iOrderType = 4 Then
text = "DVN date"
ElseIf iOrderType = 11 Then
text = "Lab Order Date"
Else
text = "Order Date"
End If
Dim cell As TableCell = gvOrders.HeaderRow.Cells(6)
Dim button As IButtonControl = If(cell.HasControls(), TryCast(cell.Controls(0), IButtonControl), Nothing)
If button Is Nothing Then
cell.Text = text
Else
button.Text = text
End If