Repost: DataGrid column width bug

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
 
M

Matt Berther

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)"
 
R

Rick Spiewak

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)"
 
M

Matt Berther

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.
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top