limit colunm width in gridview

  • Thread starter Thread starter graphicsxp
  • Start date Start date
G

graphicsxp

Hi,
I've come across a few solutions on the forum for this problem but it
still don't work :(

I have a column that can contains very long text value. I was hoping
the value would be truncated to the size of the column's width. So I
did the following :

Protected Sub grdCuttings_RowCreated(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.GridViewRowEventArgs) Handles
grdCuttings.RowCreated
Dim iWidth As Integer = 100
If e.Row.RowType = DataControlRowType.DataRow Then
For r As Integer = 0 To Me.grdCuttings.Columns.Count - 1
Me.grdCuttings.Columns(r).ItemStyle.Width = iWidth
Me.grdCuttings.Columns(r).ItemStyle.Wrap = False
Next
End If
End Sub
It changes the width but the text is wrapped instead of being
truncated..

Can you help ?
 
Um... you can't really... actually that's not true.

You can specify a number of characters to place in the field, but your
users may have different font settings to you, and their text will wrap
anyway.

You can try setting the no-wrap CSS attribute on your cells and
specifying overflow: hidden; but I don't know how well that will work.
It's not the sort of thing you tend to do very often on a webpage.
 
Back
Top