Header Text disappears when setting SortExpression

Discussion in 'ASP .Net Datagrid Control' started by Selden McCabe, Aug 15, 2004.

  1. 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
    Selden McCabe, Aug 15, 2004
    #1
    1. Advertising

  2. 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
    Selden McCabe, Aug 15, 2004
    #2
    1. Advertising

  3. 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!
    Selden McCabe, Aug 15, 2004
    #3
  4. Just enjoying watching you discuss this with yourself! <grin>


    "Selden McCabe" <> wrote in message
    news:%...
    > 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!
    >
    >
    Ken Cox [Microsoft MVP], Aug 15, 2004
    #4
  5. Hi Ken, Glad to provide some entertainment! <g>
    Selden McCabe, Aug 15, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UGF1bA==?=

    SortExpression makes SortCommand event not to trig

    =?Utf-8?B?UGF1bA==?=, Sep 22, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    470
    =?Utf-8?B?UGF1bA==?=
    Sep 22, 2005
  2. =?Utf-8?B?UGF1bA==?=

    Setting SortExpression programmatically

    =?Utf-8?B?UGF1bA==?=, Sep 26, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    6,001
    Kalpesh
    Sep 27, 2005
  3. fabrice
    Replies:
    1
    Views:
    788
    addup
    Dec 6, 2005
  4. =?Utf-8?B?SmFtZXMgUm9zZXdlbGw=?=

    GridView and SortExpression after Column Removed

    =?Utf-8?B?SmFtZXMgUm9zZXdlbGw=?=, Feb 26, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    3,290
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Feb 27, 2006
  5. JJ
    Replies:
    3
    Views:
    664
    Mark Rae
    Jun 8, 2007
Loading...

Share This Page