Truncate text in column

Discussion in 'ASP .Net Datagrid Control' started by Joe, Dec 7, 2004.

  1. Joe

    Joe Guest

    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, Dec 7, 2004
    #1
    1. Advertising

  2. Joe

    Elton Wang Guest

    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



    >-----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, Dec 10, 2004
    #2
    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. Yannick Turgeon

    Regexp to truncate

    Yannick Turgeon, Oct 11, 2003, in forum: Perl
    Replies:
    1
    Views:
    429
    Yannick Turgeon
    Oct 13, 2003
  2. Eddie
    Replies:
    1
    Views:
    9,666
    Arthur Yousif
    Dec 23, 2003
  3. Replies:
    4
    Views:
    507
    Jack Klein
    Jun 5, 2004
  4. Natevw

    truncate end of file

    Natevw, Nov 3, 2004, in forum: C++
    Replies:
    1
    Views:
    3,166
    Victor Bazarov
    Nov 3, 2004
  5. Amit Kulkarni

    HOW-TO Truncate first line in a file to zero length?

    Amit Kulkarni, Jun 22, 2004, in forum: C Programming
    Replies:
    4
    Views:
    3,647
    dbtid
    Jun 23, 2004
Loading...

Share This Page