Repost: DataGrid column width 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
 
Hello Jeremy,

I responded to your previous post about this. Did that solution not work out for you?

"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)"
 
Datagrids generate HTML tables, which are notorious for doing whatever they
want, no matter how hard you beat them.
Try putting <div> controls with the parameters you want inside the cells.
You may have to do this by editing the templates in HTML mode to get the
results you want.

Matt Berther said:
Hello Jeremy,

I responded to your previous post about this. Did that solution not work out for you?

"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)"
 
Hello Rick,
Datagrids generate HTML tables, which are notorious for doing whatever
they
want, no matter how hard you beat them.
Try putting <div> controls with the parameters you want inside the
cells.
You may have to do this by editing the templates in HTML mode to get
the
results you want.

Yes, I fought this for quite some time when trying to create a datagrid where the header stays in place while the content scrolls. However, I did get around this using the code example I sent to Jeremy.
 
Back
Top