Setting the width of a datagridColumn

T

tshad

I am building my DataGrid dynamically and am trying to set the width but am
having a problem with it.

If I do:

DataGrid1.Columns(0).Width = New Unit("65px")

I get the error:

'Width' is not a member of 'System.Web.UI.WebControls.DataGridColumn'.

Or

Dim column as BoundColumn = new BoundColumn()
column.Width = new Unit("100px")

I get the error:

'Width' is not a member of 'System.Web.UI.WebControls.BoundColumn'.

Or

column.ItemStyle-Width = new Unit(100px)

I get the error:

Method arguments must be enclosed in parentheses

How can I set the width of the column? I don't want the system to decide
which size to make the columns.

Thanks,

Tom
 
T

tshad

I tried:

column.ItemStyle.Width = Unit.Pixel(200)
column.HeaderStyle.Width = Unit.Pixel(200)

And I am not getting an error now, but the size of the column is still not
changed. I am getting the following results in the view source of the page:

<table cellspacing="0" cellpadding="1" rules="all" border="1"
id="_ctl1"
style="color:Black;background-color:Beige;height:400px;width:600px;border-collapse:collapse;">
<tr style="background-color:Brown;">
<td
style="width:200px;">UserID</td><td>FirstName</td><td>LastName</td><td>Title</td><td>Email</td>
</tr>

The width is there but the size of the column is still about 40px.

Why is that?

Thanks,

Tom
 
B

bruce barker

you need to specify an overflow style that allows the table to honor the
width, as the default is to be at as large as the content.

-- bruce (sqlwork.com)
 
T

tshad

bruce barker said:
you need to specify an overflow style that allows the table to honor the
width, as the default is to be at as large as the content.

I am not sure how I would use the overflow style in one cell, but I did find
the problem and it was in the data.

I found the problem was with cells that have long data with no spaces to
break on.

I have the following file that I took from my view source of my page.

I have a table that has 5 cells of defined lengths
(50px,50px,50px,50px,200px)

I found that normally, the table is correct and displays fine. If the data
is too long
it wraps to the next line, which is fine (if there are spaces in the data).

The problem is when I there is a long email where there are no spaces in the
text for the program to break on.

This causes the table to increase the size of the Email cell and all the
other cells are decreased proportionally.

I can substring the data to smaller length but then you lose part of the
email if a person happens to have a very long email name.

Here is an example of the file and table that resulted:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>:: Stw1::</title>
</head>
<body id="myBody">
<br><br>
<table cellspacing="0" cellpadding="1" rules="all" border="1" id="_ctl1"
style="color:Black;background-color:Beige;width:600px;border-collapse:collapse;">
<tr style="background-color:Brown;">
<td style="width:100px;">UserID</td>
<td style="width:100px;">FirstName</td>
<td style="width:100px;">LastName</td>
<td style="width:100px;">Title</td>
<td style="width:200px;">Email</td>
</tr>
<tr>
<td style="width:100px;">152</td>
<td style="width:100px;">Tom</td>
<td style="width:100px;">Lawrence</td>
<td style="width:100px;">CTO1</td>
<td style="width:200px;">[email protected]</td>
</tr>
<tr style="background-color:Gainsboro;">
<td style="width:100px;">154</td>
<td style="width:100px;">Brandon</td>
<td style="width:100px;">Franklin</td>
<td style="width:100px;">Owner</td>
<td
style="width:200px;">[email protected]</td>
</tr>
</table>
</body>
</html>

As you can see the last <td> is the problem. This normally doesn't happen,
but every once and a while it does and messes up the table. I am not sure
how best to solve the problem yet.

I was thinking that the datagrid wasn't getting built correctlly but it was
the data that caused the problem.

Thanks,

Tom
 

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,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top