Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

Re: autosize columns of gridview

 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      12-12-2006
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]
Guest
Posts: n/a
 
      12-13-2006
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...

e.g.

========================
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 /
GridView1.Columns.Count);

}

}
=====================

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



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

 
Reply With Quote
 
 
 
Reply

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



Advertisments