471,071 Members | 1,205 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,071 software developers and data experts.

Gridview Column Width

I have a Gridview binding to a DataTable source. I'd like to set the
column with of the second column. I cannot do this apparently because
when AutoGenerateColumns=true, they do not appear in the columns
collection.

I modified the RowCreated even to gridview, and I can change
properties on the cells, but not width. (setting tooltip, background
color, etc, all work but changing width has no effect). Here's
sample code I am using:

//Inside RowCreated Gridview Even
if (e.Row.RowType == DataControlRowType.DataRow)
{
foreach (TableCell tCell in e.Row.Cells)
{
tCell.ControlStyle.Width = 600; //no effect
tCell.Width = 600; //no effect
}
}

So the main question is, "Any way possible to change Gridview Column
Width with a DataTable source and AutoGenerateColumns=true?" Please
Help, I am at a loss here and been working on this for days....

-Yin

PS
little more background- I have a dynamic DataTable (could be 1 to
over 3000 columns), so I must have AutoGenerateColumns=true (I can't
set it to false, and create a boundfield for an unknown dynamic sized
table).
Dec 10 '07 #1
4 25295
Liz

<< little more background- I have a dynamic DataTable (could be 1 to
over 3000 columns), so I must have AutoGenerateColumns=true (I can't
set it to false, and create a boundfield for an unknown dynamic sized
table) >>

you're kidding, right? up to 3000 columns? .... this is software ... to be
used by humans ... not alchemy

leaving that aside (which you should not) it doesn't seem advisable to alter
column width every time a row is created; have you considered all the work
for the processor you're creating here .... I hate to ask how many rows
there may be in the control ...
"Yin99" <ws@ziowave.comwrote in message
news:7c**********************************@b40g2000 prf.googlegroups.com...
>I have a Gridview binding to a DataTable source. I'd like to set the
column with of the second column. I cannot do this apparently because
when AutoGenerateColumns=true, they do not appear in the columns
collection.

I modified the RowCreated even to gridview, and I can change
properties on the cells, but not width. (setting tooltip, background
color, etc, all work but changing width has no effect). Here's
sample code I am using:

//Inside RowCreated Gridview Even
if (e.Row.RowType == DataControlRowType.DataRow)
{
foreach (TableCell tCell in e.Row.Cells)
{
tCell.ControlStyle.Width = 600; //no effect
tCell.Width = 600; //no effect
}
}

So the main question is, "Any way possible to change Gridview Column
Width with a DataTable source and AutoGenerateColumns=true?" Please
Help, I am at a loss here and been working on this for days....

-Yin

PS
little more background- I have a dynamic DataTable (could be 1 to
over 3000 columns), so I must have AutoGenerateColumns=true (I can't
set it to false, and create a boundfield for an unknown dynamic sized
table).

Dec 10 '07 #2
On Dec 10, 11:10 am, "Liz" <l...@tiredofspam.comwrote:
<< little more background- I have a dynamic DataTable (could be 1 to
over 3000 columns), so I must have AutoGenerateColumns=true (I can't
set it to false, and create a boundfield for an unknown dynamic sized
table) >>

you're kidding, right? up to 3000 columns? .... this is software ... to be
used by humans ... not alchemy

leaving that aside (which you should not) it doesn't seem advisable to alter
column width every time a row is created; have you considered all the work
for the processor you're creating here .... I hate to ask how many rows
there may be in the control ...

"Yin99" <w...@ziowave.comwrote in message

news:7c**********************************@b40g2000 prf.googlegroups.com...
I have a Gridview binding to a DataTable source. I'd like to set the
column with of the second column. I cannot do this apparently because
when AutoGenerateColumns=true, they do not appear in the columns
collection.
I modified the RowCreated even to gridview, and I can change
properties on the cells, but not width. (setting tooltip, background
color, etc, all work but changing width has no effect). Here's
sample code I am using:
//Inside RowCreated Gridview Even
if (e.Row.RowType == DataControlRowType.DataRow)
{
foreach (TableCell tCell in e.Row.Cells)
{
tCell.ControlStyle.Width = 600; //no effect
tCell.Width = 600; //no effect
}
}
So the main question is, "Any way possible to change Gridview Column
Width with a DataTable source and AutoGenerateColumns=true?" Please
Help, I am at a loss here and been working on this for days....
-Yin
PS
little more background- I have a dynamic DataTable (could be 1 to
over 3000 columns), so I must have AutoGenerateColumns=true (I can't
set it to false, and create a boundfield for an unknown dynamic sized
table).- Hide quoted text -

- Show quoted text -
nope, it's a timespread and not really processor intensive. but still
the question remains, why in the world
can I not change a column width to a DataTable source with
AutoGenerateColumns=true?
Woudln't this be something a lot of people would want to do?

I can't imagine the only answer is to turn AutoGenerateColumns=false,
and add a bound field, map this
to the datatable, etc. Please, anyone out there know the answer?
Thanks!

Dec 10 '07 #3
i was able to make a workaround by adding a bunch of spaces to the
header row column but
still unable to get the .Width property to explicitly change the
column width on header row or
datarows.

here's sample code:

if (e.Row.RowType == DataControlRowType.Header)
{
if (e.Row.Cells[1].Text == "Column Header Text")
{
e.Row.Cells[1].Wrap = false;
e.Row.Cells[1].Width = Unit.Percentage(1000);
e.Row.Cells[1].Text = "Column Header Text " +
"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp" +
"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp" +
"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp" +
"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp" +
"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp" +
"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp" +
"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp" +
"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp";
}
Dec 10 '07 #4
Liz

"Yin99" <ws@ziowave.comwrote in message
news:56**********************************@d27g2000 prf.googlegroups.com...
>i was able to make a workaround by adding a bunch of spaces to the
header row column but
still unable to get the .Width property to explicitly change the
column width on header row or
datarows.

well ... I fooled around with this and I can get .Width property to
"influence" the width of the cell; if I set it to 5, it'll make it as small
as possible, and if I set it to 2000, it'll make it as wide as possible ...
but it will not just use the metric supplied absolutely

but here's the thing: if you look at the HTML source you should see:

<td style="width:2000px;">

if you set your Width to 2000, for example; so the code does what you ask
it to but the browser (IE6 in this case) just renders it as it "wants to"
.....
here's sample code:

if (e.Row.RowType == DataControlRowType.Header)
{
if (e.Row.Cells[1].Text == "Column Header Text")
{
e.Row.Cells[1].Wrap = false;
e.Row.Cells[1].Width = Unit.Percentage(1000);
e.Row.Cells[1].Text = "Column Header Text " +
"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp" +
"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp" +
"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp" +
"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp" +
"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp" +
"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp" +
"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp" +
"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp";
}


Dec 11 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by msch-prv | last post: by
6 posts views Thread by =?Utf-8?B?TWlrZSBQYXJyaXM=?= | last post: by
3 posts views Thread by =?Utf-8?B?SmVu?= | last post: by
5 posts views Thread by mohaaron | last post: by
2 posts views Thread by =?Utf-8?B?cm9kY2hhcg==?= | last post: by
2 posts views Thread by mohaaron | last post: by
1 post views Thread by Durango2008 | last post: by
2 posts views Thread by =?Utf-8?B?ZG1idXNv?= | last post: by
1 post views Thread by =?Utf-8?B?ZG1idXNv?= | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.