Re: autosize columns of gridview

Discussion in 'ASP .Net' started by Eliyahu Goldin, Dec 12, 2006.

  1. 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" <> wrote in message
    news:D...
    > is there a way to size the columns in a gridivew that that has
    > autogenerate=true
    Eliyahu Goldin, Dec 12, 2006
    #1
    1. Advertising

  2. 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.
    Steven Cheng[MSFT], Dec 13, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dennis Strickland via .NET 247

    How to autosize the row heigth in a Datagrid

    Dennis Strickland via .NET 247, Jun 14, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,351
    Uri Dor
    Jun 15, 2004
  2. raymond chiu

    set autosize of datagrid to no

    raymond chiu, Dec 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,711
    Christopher Reed
    Dec 29, 2005
  3. Jeff

    newbie: autosize

    Jeff, Jul 14, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    1,845
  4. Jacksm
    Replies:
    2
    Views:
    839
    Paul Chalekian
    Nov 21, 2006
  5. Vinki

    template columns and bound columns in gridview

    Vinki, Apr 25, 2007, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    847
    Vinki
    Apr 25, 2007
Loading...

Share This Page