DataGrid Column Width

F

frank

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 DataGridTableStyle, but I can't get this to
work with web pages.

Any help would be appreciated.
 
S

Saravana

you can programmatically change width of the column like this,

datagrid1.Columns(0).ItemStyle.Width.Pixel(150)

or

datagrid1.Columns(0).ItemStyle.Width = new Unit(150,UnitType.Pixel)
 
I

Ignacio Machin

Hi Frank,

You can use DataGrid.Columns[X].ItemStyle.Width , here goes an example:
this.locationgrid.Columns[2].Visible = this.locationgrid.Columns[3].Visible
= false;

this.locationgrid.Columns[1].ItemStyle.Width= 460;



Hope this help,
 
E

Eliyahu Goldin

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top