Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Re: autosize columns of gridview

Thread Tools

Re: autosize columns of gridview

Eliyahu Goldin
Posts: n/a
You can try. You can access the autogenerated columns only in ItemCreated
event. At this stage you can set their properties. Just keep in mind that
you don't have full control over column width. The browser treats your
instructions as recommendations.

Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

"igotyourdotnet" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> is there a way to size the columns in a gridivew that that has
> autogenerate=true

Reply With Quote
Steven Cheng[MSFT]
Posts: n/a
Hi Mike,

As Eliyahu has suggested, you can programmatically access those
autogenerated columsn in GridView and adjust their properties. Based on my
test, the autogenerated columns has been accessible in the following events:

Init, Load, PreRender...


protected void GridView1_Init(object sender, EventArgs e)
GridView1.Width = 500;
Response.Write("<br/>Init Count: " + GridView1.Columns.Count);

foreach (DataControlField field in GridView1.Columns)
field.ItemStyle.Width = Unit.Percentage(100 /



Hope this helps.


Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
template columns and bound columns in gridview Vinki ASP .Net Web Controls 2 04-25-2007 04:22 PM
Align table columns with gridview columns Jacksm ASP .Net 2 11-21-2006 09:49 PM
newbie: autosize Jeff ASP .Net 3 07-14-2006 05:57 PM
set autosize of datagrid to no raymond chiu ASP .Net 1 12-29-2005 04:23 AM
How to autosize the row heigth in a Datagrid Dennis Strickland via .NET 247 ASP .Net 1 06-15-2004 11:42 AM