Truncate text in column

J

Joe

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

Elton Wang

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
(e-mail address removed)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top