473,228 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,228 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 25484
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: msch-prv | last post by:
I have difficulties adjusting the column width of a gridview control. The column width changes appear in the design grid, but at run-time the width changes back to what I presume are the grid's...
6
by: =?Utf-8?B?TWlrZSBQYXJyaXM=?= | last post by:
I am trying to set the width of one of the columns of an asp.net 2.0 Gridview control. I am using a line - MyGridview.Columns.ItemStyle.Width = Unit.Percentage(40); The problem is that there...
3
by: =?Utf-8?B?SmVu?= | last post by:
I would like to set the width on 2 columns of a asp.net gridview control, but I'm having trouble making this work. Here is the code I use to create the gridview: 'Create a new data table...
5
by: mohaaron | last post by:
OK, I have now gone through lots of posts, and there are lots, looking for a anwer as to why I can't set the width of the columns in my gridview. So far I have tried the following methods to set...
2
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, can someone please tell me how to make a gridview column fixed-width? When I resize the browser the columns auto adjust somehow and i can't figure out how to make that stop for one of my...
2
by: mohaaron | last post by:
Why does it seem like is impossible to set the width of a BoundField in a GridView. I've tried all sorts of different way to set the width and none of them work. So far the only thing I've done...
1
by: Durango2008 | last post by:
Hi, I am having a bit of trouble with my gridview table and the width of the columns. The gridview is made of Templates that contain LinkButton controls. The LinkButtons will display a string...
2
by: =?Utf-8?B?ZG1idXNv?= | last post by:
How do I increase the default width of a gridview column (just one column, the 10th column, named "Notes")? In design mode, I changed the width properties of the HeaderStyle, ControlStyle, and...
1
by: =?Utf-8?B?ZG1idXNv?= | last post by:
How do I increase the default width of a gridview column (just one column, the 10th column, named "Notes")? In design mode, I changed the width properties of the HeaderStyle, ControlStyle, and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...

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.