Header Text disappears when setting SortExpression

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
 
S

Selden McCabe

Here is some additional information that seems to bear on this:

I also want some of the column headers to have two rows. The way I
accomplished this was to insert %p% in the text where I want a line break.
Then, in the ItemDataBound event, for headers, Items, and AlternatingItems,
I replace %p% with <br>.

If I comment out that event, and set the sortexpression, I see my text in
the headers.

So maybe my question should be more like, how can I control the number of
lines of text in the header, with AllowSorting=True?

---Selden
 
S

Selden McCabe

Now I feel really stupid!
After that last post, I thought about it some more, and realized that, with
the link that the sort creates, just adding <br> in the string wasn't
correct HTML syntax.
Now I use "<p>First Line<br>Second Line</p>" for the header text, and
everything works!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top