Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

Setting the width of a datagridColumn

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tshad - 29 Aug 2007 18:42 GMT
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
tshad - 29 Aug 2007 18:53 GMT
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

>I am building my DataGrid dynamically and am trying to set the width but am
>having a problem with it.
[quoted text clipped - 30 lines]
>
> Tom
bruce barker - 29 Aug 2007 19:31 GMT
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)

> I tried:
>
[quoted text clipped - 54 lines]
>>
>> Tom
tshad - 29 Aug 2007 19:59 GMT
> 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;">tlawrence@ftsw2.com</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;">brandonlFranklinfromtesting@sprint.blackberry.net</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

> -- bruce (sqlwork.com)
>
[quoted text clipped - 57 lines]
>>>
>>> Tom

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.