Truncate text in column

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

  1. #1

    Default Truncate text in column

    Does anyone know a way to truncate the text in a column such that the text
    doesn't wrap to a second line? With winform you can MeasureString using the
    Font, but I can't find a way to use that with asp.net.

    One thought occurred to me - turn off "wrap text within cells", but that
    makes the grid as a whole widen out. Perhaps I can set the width of the
    column back to it's proper value after the data loads up?

    Thanks!



    Joe Guest

  2. Similar Questions and Discussions

    1. Two-column text inside one-column text box?
      Hello everybody, I'm working on a small size book with a one-column text box threaded through the whole thing. There are some short lists that I'd...
    2. PHP Truncate Text
      Can anyone please tell me how to truncate dynamic PHP text - is there aan extension available that does this ?? Thanks............
    3. hyperlink column text. Where is it??
      Does anyone have any idea how to get the text out of a hyperlink column in a web datagrid? It's a hyperlink column, not a template column so...
    4. Image in header column (not replacing column header text)
      I have a sortable (asc/desc) datagrid and would like to add a small arrow icon (down/up) next to the column header text to improve the UI. Is this...
    5. Q: Get Text from Hyperlink Column
      Hi, I have a column in my DataGrid which is a Hyperlink Column. Everything work find except when I try to get the text of the column using...
  3. #2

    Default Truncate text in column

    Hi Joe,

    You can truncate the text in a column from
    DataGrid_ItemDataBound event. The sample code as follows:

    DataRowView drv = (DataRowView)e.Item.DataItem;
    TableCell cell = (TableCell)e.Item.Controls[columnIndex];
    cell.Text = drv[columnIndex].Tostring().Substring(0,
    length);

    Hope it's helpful to you.

    Elton Wang
    [email]elton_wang@hotmail.com[/email]

    >-----Original Message-----
    >Does anyone know a way to truncate the text in a column
    such that the text
    >doesn't wrap to a second line? With winform you can
    MeasureString using the
    >Font, but I can't find a way to use that with asp.net.
    >
    >One thought occurred to me - turn off "wrap text within
    cells", but that
    >makes the grid as a whole widen out. Perhaps I can set
    the width of the
    >column back to it's proper value after the data loads up?
    >
    >Thanks!
    >
    >
    >
    >.
    >
    Elton Wang 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