Header Text disappears when setting SortExpression

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default Header Text disappears when setting SortExpression

    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 Guest

  2. Similar Questions and Discussions

    1. text disappears
      I used Contribute to edit two small sites of mine. One of them works fine so I know this program is working but with the other it doesn't work. The...
    2. Setting the SOAP header value?
      Hi, I'm using .NET 1.1 and Visual Studio 2003. I just want understand something on setting the SOAP headers in a client app. At... ...
    3. Static Text Disappears
      Wow.. the problem I have is pretty weird. I even scanned the whole computer for viruses because I couldn't believe what was happening. Here's...
    4. [PHP] setting header() for csv file
      Hi again -- ...and then David T-G said... % ... % How do I construct the headers so that the browser says "Oh, this is a It turns out that...
    5. Text disappears when sized over 14
      Sometimes the text in a text box cannot be seen (on stage) when the font is sized 14 or over. I know the text is still there as when I click on...
  3. #2

    Default Re: Header Text disappears when setting SortExpression

    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 Guest

  4. #3

    Default Re: Header Text disappears when setting SortExpression

    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 Guest

  5. #4

    Default Re: Header Text disappears when setting SortExpression

    Just enjoying watching you discuss this with yourself! <grin>


    "Selden McCabe" <smccabe@integrantInc.com> wrote in message
    news:%23jqjNolgEHA.1184@TK2MSFTNGP12.phx.gbl...
    > 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] Guest

  6. #5

    Default Re: Header Text disappears when setting SortExpression

    Hi Ken, Glad to provide some entertainment! <g>


    Selden McCabe Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139