Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datagrid column width

Status
Not open for further replies.

lfc77

Programmer
Aug 12, 2003
218
0
0
GB
How do you set the width of a column in a datagrid to a particular value?

Thanks,

lfc77
 
Hi,

Iterate through the datagrids Items collection and each Items Cells collection - you can then set the width of each cell. If the datagrid is anything like a table (which I suspect it is) you probably only need to set the widths of the first Items cells.

- set it at server
mygrid.Items[y].Cells[x].Attributes.Width = 50;

- add width to set in client
mygrid.Items[y].Cells[x].Attributes.Add ("width","50");

Hope this helps...

Cheers.
 
Hi,

Iterate through the datagrids Items collection and each Items Cells collection - you can then set the width of each cell. If the datagrid is anything like a table (which I suspect it is) you probably only need to set the widths of the first Items cells.

- set it at server
mygrid.Items[y].Cells[x].Width = 50;

- add width to set in client
mygrid.Items[y].Cells[x].Attributes.Add ("width","50");

Hope this helps...

Cheers.
 
Thanks Gazzer,

I was actually looking for a way to do this in the HTML in my <Columns> tag. I thought that using a Template Column would be the best way, but I can't find any decent sites showing how to set it up the way I want. Currently the column looks like this :

<asp:BoundColumn DataField=&quot;InceptTime&quot; HeaderText=&quot;InceptTime&quot; SortExpression=&quot;InceptTime&quot; />

Basically, I want to find some way of setting the width of this column.


Cheers,

Mike

 
Thanks Gazzer,

I was actually looking for a way to do this in the HTML in my <Columns> tag. I thought that using a Template Column would be the best way, but I can't find any decent sites showing how to set it up the way I want. Currently the column looks like this :

<asp:BoundColumn DataField=&quot;InceptTime&quot; HeaderText=&quot;InceptTime&quot; SortExpression=&quot;InceptTime&quot; />

Basically, I want to find some way of setting the width of this column.


Cheers,

lfc77

 
Item-Style Width doesn't work but that may be because I have the datagrid within <div> tags to allow scrolling.
 
Are you using vs.net? You could always just modify them through the columns dialog box in the datagrid properties.

Alternately, you should just be able to add Width=value in your column tag, and that should do it.

D'Arcy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top