S
Selden McCabe
I have a datagrid that I want to set the column header text, column width,
bound data field, and sortexpression in code at run time.
This was working fine until I added the sortexpression, at which point the
headers disappeared!
Here is the code:
Private Sub AddColumn(ByVal sHeader As String, ByVal sDataColumn As String,
ByVal nWidth As Integer)
Dim bc1 As New BoundColumn
bc1.SortExpression = sDataColumn
bc1.DataField = sDataColumn
bc1.HeaderText = sHeader
bc1.HeaderStyle.Width = System.Web.UI.WebControls.Unit.Pixel(nWidth)
bc1.ItemStyle.Width = System.Web.UI.WebControls.Unit.Pixel(nWidth)
DataGrid1.Columns.Add(bc1)
End Sub
On the page_load, I do a bunch fo AddColumns, then generate a dataview with
the data, and bind it to the grid.
If I comment out the line that sets the SortExpression, the grid looks
great. If I add it back in, the header collapses to a couple of pixels
tall.
I've tried moving the SortExpression = line around, and even setting the
header text AFTER the grid gets databound, but none of these had any effect.
What am I doing wrong? Any suggestions would be very welcome!
Thanks,
---Selden
bound data field, and sortexpression in code at run time.
This was working fine until I added the sortexpression, at which point the
headers disappeared!
Here is the code:
Private Sub AddColumn(ByVal sHeader As String, ByVal sDataColumn As String,
ByVal nWidth As Integer)
Dim bc1 As New BoundColumn
bc1.SortExpression = sDataColumn
bc1.DataField = sDataColumn
bc1.HeaderText = sHeader
bc1.HeaderStyle.Width = System.Web.UI.WebControls.Unit.Pixel(nWidth)
bc1.ItemStyle.Width = System.Web.UI.WebControls.Unit.Pixel(nWidth)
DataGrid1.Columns.Add(bc1)
End Sub
On the page_load, I do a bunch fo AddColumns, then generate a dataview with
the data, and bind it to the grid.
If I comment out the line that sets the SortExpression, the grid looks
great. If I add it back in, the header collapses to a couple of pixels
tall.
I've tried moving the SortExpression = line around, and even setting the
header text AFTER the grid gets databound, but none of these had any effect.
What am I doing wrong? Any suggestions would be very welcome!
Thanks,
---Selden