473,792 Members | 3,076 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGrid Column Width

How do I set the column width of a column in a DataGrid programatically (in
ASP.NET web pages)?

I understand I may have to use DataGridTableSt yle, but I can't get this to
work with web pages.

Any help would be appreciated.
Nov 15 '05 #1
3 31124
you can programmaticall y change width of the column like this,

datagrid1.Colum ns(0).ItemStyle .Width.Pixel(15 0)

or

datagrid1.Colum ns(0).ItemStyle .Width = new Unit(150,UnitTy pe.Pixel)
--
Saravana
Microsoft India Community Star,
MCAD,SE,SD,DBA.
"frank" <fr***@frank.co m> wrote in message
news:#m******** ******@TK2MSFTN GP12.phx.gbl...
How do I set the column width of a column in a DataGrid programatically (in ASP.NET web pages)?

I understand I may have to use DataGridTableSt yle, but I can't get this to
work with web pages.

Any help would be appreciated.

Nov 15 '05 #2
Hi Frank,

You can use DataGrid.Column s[X].ItemStyle.Widt h , here goes an example:
this.locationgr id.Columns[2].Visible = this.locationgr id.Columns[3].Visible
= false;

this.locationgr id.Columns[1].ItemStyle.Widt h= 460;

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"frank" <fr***@frank.co m> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
How do I set the column width of a column in a DataGrid programatically (in ASP.NET web pages)?

I understand I may have to use DataGridTableSt yle, but I can't get this to
work with web pages.

Any help would be appreciated.

Nov 15 '05 #3
Just remember, that whatever you do in the code, meaning whatever HTML it
produces, a browser on client's machine will consider it as a recomendation
rather than an instruction.

Since you can hardly be sure what width the browser will assign to your
columns, it's not a good idea to rely on exact column width in your design.

Eliyahu

"Saravana" <sa******@sct.c o.in> wrote in message
news:e$******** ******@TK2MSFTN GP12.phx.gbl...
you can programmaticall y change width of the column like this,

datagrid1.Colum ns(0).ItemStyle .Width.Pixel(15 0)

or

datagrid1.Colum ns(0).ItemStyle .Width = new Unit(150,UnitTy pe.Pixel)
--
Saravana
Microsoft India Community Star,
MCAD,SE,SD,DBA.
"frank" <fr***@frank.co m> wrote in message
news:#m******** ******@TK2MSFTN GP12.phx.gbl...
How do I set the column width of a column in a DataGrid programatically

(in
ASP.NET web pages)?

I understand I may have to use DataGridTableSt yle, but I can't get this to work with web pages.

Any help would be appreciated.


Nov 15 '05 #4

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

Similar topics

3
366
by: Eva | last post by:
How do i indivually change the width of a datagrid coloumn? I am currently using the PrefferedColoumnWidth property, but due to space restrictions i do not want all the columns at the same width. Any help is appreciated.
1
11629
by: | last post by:
How do I change the datagrid column width dynamically when the grid's being loaded? VM
0
806
by: Randy | last post by:
Hello, I'm trying to find out if there is a way to set a DataGrid column width (or tableStyle column width) to be auto-expanded to encompass the widest text in that column...to be auto-expanded rather than grabbing the widest text string that will be displayed in that column and setting the width. Is there a way to make the column width auto-expanded? Thanks
0
1035
by: RA | last post by:
How can I get the datagrid column width when the user changes it? Thanks
1
3260
by: Amos | last post by:
Can I add a column to the datagrid and also resize it? I add them like this: DataTableAddress.Columns.Add("Col1", typeof(string)); DataTableAddress.Columns.Add("Col2", typeof(string)); DataTableAddress.Columns.Add("Col3", typeof(string)); I'd like to add to resize them without using a datacolumn because there's over 30 columns and because the application is working well already (I don't know how the datacolumn additions will affect the...
2
2717
by: nj | last post by:
I am trying to set the width of a single column in the datagrid. What is happening is the column seems to stretch to try to accomodate the length of the data contained in it. I want to have it only x number of pixels wide and the data to wrap if necessary. I have tried several things to set the column width but it seems to ignore everything I try. I have tried: 1. Setting the width of the grid to be 50% - still stretches across entire...
3
6478
by: Mike Fellows | last post by:
Im trying to set the column width of individual datgrid columns I can set the column widths of all the columns at once using Me.DataGrid1.PreferredColumnWidth = 100 But I am unable to set the individual column widths Also the source from where my data is coming from the first column contains a date and time i.e. 01/01/2003 12:00:00 but within the datagrid it displays 01/01/2003 and i need it
1
3191
by: salih ataoz | last post by:
i have a form1 and i put Datagrid1 on it and i want to change its column width and row hight ex: datagrid1.column(0).width=200 datagrid1.row(0).width=100 or datagrid1.allcolumnwidth=200
0
1428
by: Claire | last post by:
Hi, Visual Studio 2003 The application Im writing is skinned and therefore i need to be able to write my own code for manipulating and drawing headers for a data grid outside of the control. I created and populated a dataset (source at end of mail) and bound it to a grid for testing. For the datagrid, I used a tablestyles object mapped to table "box". I add gridcolumnstyles for each column and set the 'Icon' column width to 32
3
2059
by: Francois | last post by:
Hello, How can I size my text to fit in a datagrid column ? I do not want the datagrid go multiline. I am using WEB Forms, not windows form, so CreateGraphics ans MesasureString do not work. Thanks.
0
9518
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10430
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10211
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10159
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9033
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3719
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.