Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Truncate text in column

Reply
Thread Tools

Truncate text in column

 
 
Joe
Guest
Posts: n/a
 
      12-07-2004
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!



 
Reply With Quote
 
 
 
 
Elton Wang
Guest
Posts: n/a
 
      12-10-2004
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
http://www.velocityreviews.com/forums/(E-Mail Removed)


>-----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!
>
>
>
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView - Setting the text of the 'select' column to the value of another column Greg Smith ASP .Net 0 04-12-2007 03:11 PM
GridView - Setting the text of the 'select' column to the value of another column Greg Smith ASP .Net Web Controls 0 04-12-2007 02:40 PM
Image in header column (not replacing column header text) hansiman ASP .Net Datagrid Control 3 02-07-2004 12:17 AM
truncate time from date in DataTable.Select() Eddie ASP .Net 1 12-23-2003 10:55 PM
Regexp to truncate Yannick Turgeon Perl 1 10-13-2003 02:09 AM



Advertisments