Connecting Tech Pros Worldwide Forums | Help | Site Map

Gridview Column Width

Yin99
Guest
 
Posts: n/a
#1: Dec 10 '07
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).
Liz
Guest
 
Posts: n/a
#2: Dec 10 '07

re: Gridview Column Width



<< 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:7c399386-bd6d-4563-87db-f1d09241031f@b40g2000prf.googlegroups.com...
Quote:
>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).

Yin99
Guest
 
Posts: n/a
#3: Dec 10 '07

re: Gridview Column Width


On Dec 10, 11:10 am, "Liz" <l...@tiredofspam.comwrote:
Quote:
<< 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:7c399386-bd6d-4563-87db-f1d09241031f@b40g2000prf.googlegroups.com...
>
>
>
Quote:
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.
>
Quote:
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:
>
Quote:
//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
}
}
>
Quote:
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....
>
Quote:
-Yin
>
Quote:
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!

Yin99
Guest
 
Posts: n/a
#4: Dec 10 '07

re: Gridview Column Width


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";
}
Liz
Guest
 
Posts: n/a
#5: Dec 11 '07

re: Gridview Column Width



"Yin99" <ws@ziowave.comwrote in message
news:564c73f3-d7cf-49e6-8586-b85d4ee00f55@d27g2000prf.googlegroups.com...
Quote:
>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"
.....


Quote:
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";
}


Closed Thread