DataGrid Column Width is broken - is this a bug?

  • Thread starter Thread starter Jeremy
  • Start date Start date
J

Jeremy

I have googled for this issue, and many other people have the same problem
with no resolution. The data grid column sizes automatically resize based
on their contents no matter what the Style.Width is set to. I was looking
at the HTML output, and the values I entered for Width does not even get
generated.

And to make things worse, even though I set the width of the Grid to 100%,
it actually expands beyond the edge of the screen forcing the user to scroll
horizontally. Here is my code:

Private Sub AddTemplateColumn( _
ByVal InsertAt As Integer, _
ByVal itemTemplate As ITemplate, _
ByVal headerText As String, _
ByVal pixelWidth As Integer)

Dim tempColumn As New TemplateColumn

dgOptions.Columns.AddAt(InsertAt, tempColumn)

With tempColumn
.ItemTemplate = itemTemplate
.HeaderText = headerText
.ItemStyle.Width = _
New Web.UI.WebControls.Unit( _
pixelWidth, _
UnitType.Pixel)
End With
End Sub

This is driving me insane.

Thanks,
Jeremy
 
you need to remove the width setting on the datagrid control first. this
setting overrides internal settings because cells must be drawn within the
limits imposed by the datagrid control
 
it not a bug.

grids build html tables. in html css if you set with of a table cell
narrower than the content with no overflow handling specified, then the
width of the cell is expanded (check the w3c standards). for tables, all
widths are really rending hints. you can set a overflow style on the
contents of the cell and the cell width will be honored.

example:

<table border=1>
<tr>
<td style="width:80pt;">will fit</td>
<td style="width:80pt;">this_cell_is_too_width_and_will_blow_width</td>
</tr>
</table>

<table border=1>
<tr>
<td style="width:80pt">will fit</td>
<td style="width:80pt"><span
style="width:80pt;overflow:hidden">this_cell_is_too_width_and_will_be_clippe
d</span></td>
</tr>
</table>

note: <td>'s do not support the overflow style;


-- bruce (sqlwork.com)
 
you need to remove the width setting on the datagrid control first. this
setting overrides internal settings because cells must be drawn within the
limits imposed by the datagrid control

That doesnt make any sense, I WANT the grid to be 100% of the page, but it
is going beyond that.
 
grids build html tables. in html css if you set with of a table cell
narrower than the content with no overflow handling specified, then the
width of the cell is expanded (check the w3c standards). for tables, all
widths are really rending hints. you can set a overflow style on the

I thought the same thing, so I put all the text in a 5 char wide text box,
and it still happens, it's just a huge empty cell with a tiny text box with
all the text.

As I said in my original post, the width is not being written to the table,
look at the HTML output.
 
Hello Jeremy,
Private Sub AddTemplateColumn( _
ByVal InsertAt As Integer, _
ByVal itemTemplate As ITemplate, _
ByVal headerText As String, _
ByVal pixelWidth As Integer)
Dim tempColumn As New TemplateColumn

dgOptions.Columns.AddAt(InsertAt, tempColumn)

With tempColumn
.ItemTemplate = itemTemplate
.HeaderText = headerText
.ItemStyle.Width = _
New Web.UI.WebControls.Unit( _
pixelWidth, _
UnitType.Pixel)
End With
End Sub

I think you will need to set the width of the column on the datagrid itself:

ie: dgOptions.Columns.Item(InsertAt).Width = new Web.UI.WebControls.unit(pixelWidth, UnitType.Pixel)
 
Back
Top