473,382 Members | 1,349 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,382 software developers and data experts.

Why can't I set the GridView column width?

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 the width
and nothing works.

1. <asp:BoundField HeaderText="fieldName" ItemStyle-Width="300px"
DataField="fieldName" />
2. <asp:BoundField HeaderText="fieldName" HeaderStyle-Width="300px"
DataField="fieldName" />
3. This has been tried in both the RowCreated and RowDataBound events.
foreach (TableCell cell in e.Row.Cells)
{
int width = cell.Text.Length * 10;
cell.Width = Unit.Pixel(width);
}
4. This has been tried in both the RowCreated and RowDataBound events.
foreach (DataControlField field in this.searchGrid.Columns)
{
field.ItemStyle.Width = Unit.Pixel(500);
}

Why is it so diffecult to do something that should be so simple?

Nov 9 '07 #1
5 54620
On Nov 9, 7:12 pm, "mohaa...@gmail.com" <mohaa...@gmail.comwrote:
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 the width
and nothing works.

1. <asp:BoundField HeaderText="fieldName" ItemStyle-Width="300px"
DataField="fieldName" />
2. <asp:BoundField HeaderText="fieldName" HeaderStyle-Width="300px"
DataField="fieldName" />
3. This has been tried in both the RowCreated and RowDataBound events.
foreach (TableCell cell in e.Row.Cells)
{
int width = cell.Text.Length * 10;
cell.Width = Unit.Pixel(width);}

4. This has been tried in both the RowCreated and RowDataBound events.
foreach (DataControlField field in this.searchGrid.Columns)
{
field.ItemStyle.Width = Unit.Pixel(500);

}

Why is it so diffecult to do something that should be so simple?
A gridview will generate a table with columns width equal to the
ItemStyle-Width, or HeaderStyle-Width. The values 1), 2) should work
but it depends on a number of things... For example, if gridview has a
fixed width, or header is off (HeaderStyle-Width), etc.

Nov 9 '07 #2

<mo******@gmail.comwrote in message
news:11*********************@50g2000hsm.googlegrou ps.com...
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 the width
and nothing works.
1. <asp:BoundField HeaderText="fieldName" ItemStyle-Width="300px"
DataField="fieldName" />
this works ... but if you set it to "1" it will ignore the setting ... I
guess I'm not clear why you are setting/re-setting column width every time a
row is bound to the grid in the examples below ... doesn't seem to make
sense ...

2. <asp:BoundField HeaderText="fieldName" HeaderStyle-Width="300px"
DataField="fieldName" />
3. This has been tried in both the RowCreated and RowDataBound events.
foreach (TableCell cell in e.Row.Cells)
{
int width = cell.Text.Length * 10;
cell.Width = Unit.Pixel(width);
}
4. This has been tried in both the RowCreated and RowDataBound events.
foreach (DataControlField field in this.searchGrid.Columns)
{
field.ItemStyle.Width = Unit.Pixel(500);
}

Why is it so diffecult to do something that should be so simple?

Nov 9 '07 #3
OK, to answer both of your posts.

Alexey,

The GridView is not fixed with, there is no width set for it at all. I
would assume that if I set the width of the individual columns the
grid as a whole would take up the sum width of the columns. So I still
don't know why any of the methods I have tried don't work.

Barrie,

The width is not set to 1 so it should work, right? There is no
particular reason why I'm setting/re-setting the width when the row is
bound other then I thought I could use the length of the data in the
cell as a baseline for with width of the column. This of course also
not not working like everything that I have tried.

What now?

On Nov 9, 3:45 pm, "Barrie Wilson" <bwil...@nowhere.comwrote:
<mohaa...@gmail.comwrote in message

news:11*********************@50g2000hsm.googlegrou ps.com...
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 the width
and nothing works.
1. <asp:BoundField HeaderText="fieldName" ItemStyle-Width="300px"
DataField="fieldName" />

this works ... but if you set it to "1" it will ignore the setting ... I
guess I'm not clear why you are setting/re-setting column width every time a
row is bound to the grid in the examples below ... doesn't seem to make
sense ...
2. <asp:BoundField HeaderText="fieldName" HeaderStyle-Width="300px"
DataField="fieldName" />
3. This has been tried in both the RowCreated and RowDataBound events.
foreach (TableCell cell in e.Row.Cells)
{
int width = cell.Text.Length * 10;
cell.Width = Unit.Pixel(width);
}
4. This has been tried in both the RowCreated and RowDataBound events.
foreach (DataControlField field in this.searchGrid.Columns)
{
field.ItemStyle.Width = Unit.Pixel(500);
}
Why is it so diffecult to do something that should be so simple?- Hide quoted text -

- Show quoted text -

Nov 12 '07 #4
Hi

I am experiencing the very same problem as yourself, and have spent
many hours attempting to set column widths without succes. I don't
suppose you have found or been pointed in the right direction to a
solution to this have you?

Cheers

Shaun
On 12 Nov, 19:44, "mohaa...@gmail.com" <mohaa...@gmail.comwrote:
OK, to answer both of your posts.

Alexey,

TheGridViewis not fixed with, there is nowidthset for it at all. I
would assume that if I set thewidthof the individual columns the
grid as a whole would take up the sumwidthof the columns. So I still
don't know why any of the methods I have tried don't work.

Barrie,

Thewidthis not set to 1 so it should work, right? There is no
particular reason why I'm setting/re-setting thewidthwhen the row is
bound other then I thought I could use the length of the data in the
cell as a baseline for withwidthof thecolumn. This of course also
not not working like everything that I have tried.

What now?

On Nov 9, 3:45 pm, "Barrie Wilson" <bwil...@nowhere.comwrote:
<mohaa...@gmail.comwrote in message
news:11*********************@50g2000hsm.googlegrou ps.com...
OK, I have now gone through lots of posts, and there are lots, looking
for a anwer as to why I can't set thewidthof the columns in my
>gridview. So far I have tried the following methods to set thewidth
and nothing works.
1. <asp:BoundField HeaderText="fieldName" ItemStyle-Width="300px"
DataField="fieldName" />
this works ... but if you set it to "1" it will ignore the setting ... I
guess I'm not clear why you are setting/re-settingcolumnwidthevery time a
row is bound to the grid in the examples below ... doesn't seem to make
sense ...
2. <asp:BoundField HeaderText="fieldName" HeaderStyle-Width="300px"
DataField="fieldName" />
3. This has been tried in both the RowCreated and RowDataBound events.
foreach (TableCell cell in e.Row.Cells)
{
intwidth= cell.Text.Length * 10;
cell.Width= Unit.Pixel(width);
}
4. This has been tried in both the RowCreated and RowDataBound events.
foreach (DataControlField field in this.searchGrid.Columns)
{
field.ItemStyle.Width= Unit.Pixel(500);
}
Why is it so diffecult to do something that should be so simple?- Hide quoted text -
- Show quoted text -
Nov 25 '07 #5
Not sure whether this is the same for you, but I was using the CSS
Friednly adapters on my site, and this was forcing all GridView
controls on m site to te default formatting. This was being applied
dispite the fact that I was overiding this with a HeaderStyle on each
control. Commenting out the control from the
CSSFriendlyAdapters.browser file under APP_Browsers fixed my problem.

As I say, if you are using the CSS Friendly Adapters this will
probably fix it for you too. If not - I have no idea :o)

Cheers

Shaun

On 12 Nov, 19:44, "mohaa...@gmail.com" <mohaa...@gmail.comwrote:
OK, to answer both of your posts.

Alexey,

TheGridViewis not fixed with, there is nowidthset for it at all. I
would assume that if I set thewidthof the individual columns the
grid as a whole would take up the sumwidthof the columns. So I still
don't know why any of the methods I have tried don't work.

Barrie,

Thewidthis not set to 1 so it should work, right? There is no
particular reason why I'm setting/re-setting thewidthwhen the row is
bound other then I thought I could use the length of the data in the
cell as a baseline for withwidthof thecolumn. This of course also
not not working like everything that I have tried.

What now?

On Nov 9, 3:45 pm, "Barrie Wilson" <bwil...@nowhere.comwrote:
<mohaa...@gmail.comwrote in message
news:11*********************@50g2000hsm.googlegrou ps.com...
OK, I have now gone through lots of posts, and there are lots, looking
for a anwer as to why I can't set thewidthof the columns in my
>gridview. So far I have tried the following methods to set thewidth
and nothing works.
1. <asp:BoundField HeaderText="fieldName" ItemStyle-Width="300px"
DataField="fieldName" />
this works ... but if you set it to "1" it will ignore the setting ... I
guess I'm not clear why you are setting/re-settingcolumnwidthevery time a
row is bound to the grid in the examples below ... doesn't seem to make
sense ...
2. <asp:BoundField HeaderText="fieldName" HeaderStyle-Width="300px"
DataField="fieldName" />
3. This has been tried in both the RowCreated and RowDataBound events.
foreach (TableCell cell in e.Row.Cells)
{
intwidth= cell.Text.Length * 10;
cell.Width= Unit.Pixel(width);
}
4. This has been tried in both the RowCreated and RowDataBound events.
foreach (DataControlField field in this.searchGrid.Columns)
{
field.ItemStyle.Width= Unit.Pixel(500);
}
Why is it so diffecult to do something that should be so simple?- Hide quoted text -
- Show quoted text -
Nov 25 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Price Brattin | last post by:
How do I set the column width in a datagrid when the datasource is a dataview? I want to use a dataview so data changes, inserts, and deletes are disabled. I can set the column width when I use...
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...
0
by: =?Utf-8?B?Z3V5?= | last post by:
Repost as no reply from dotnet.Framework.ASPNet I have a GridView with autogenerated columns and I programatically set the width and visibility of each column. The code executes correctly as with...
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...
4
by: Yin99 | last post by:
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...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.