adjusting datagrid column width

Discussion in 'ASP .Net Datagrid Control' started by Nedu N, Jan 19, 2004.

  1. Nedu N

    Nedu N Guest

    Hi,
    I want to know what are all the ways with which we can precisely control the
    width of the datagrid columns. Iam facing problems in controlling the width
    of the datagrid columns.

    Thanks
     
    Nedu N, Jan 19, 2004
    #1
    1. Advertising

  2. Nedu N

    Teemu Keiski Guest

    Hi,

    declaratively

    ItemStyle-Width="150px"

    would work as well as if you specify it via code (via DataGrid's Columns
    collection) but then something like:

    DataGrid1.Columns(0).ItemStyle.Width=Unit.Pixel(150)

    That's all I can really say without knowing more about your scenario. If
    this doesn't help, please provide bit more details.

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist

    "Nedu N" <> wrote in message
    news:...
    > Hi,
    > I want to know what are all the ways with which we can precisely control
    > the
    > width of the datagrid columns. Iam facing problems in controlling the
    > width
    > of the datagrid columns.
    >
    > Thanks
    >
    >
     
    Teemu Keiski, Jan 19, 2004
    #2
    1. Advertising

  3. Hi Nedu,

    Thank you for using MSDN Newsgroup! My name is Jeffrey, and I will be
    assisting you on this issue.
    Based on my understanding, you want to get the fully control of the column
    width of the web form datagrid control.

    ==================================================
    1). If your column is customized column, you can control it through
    ItemStyle in the Html designer:
    <asp:TemplateColumn>
    <ItemTemplate>
    ..............
    </ItemTemplate>
    <ItemStyle Width=50px></ItemStyle>
    </asp:TemplateColumn>

    2). For auto generated column, you can control it before render(At
    runtime), like this:
    private void Page_Load(object sender, System.EventArgs e)
    {
    sqlDataAdapter1.Fill(dataSet11);
    DataGrid1.DataBind();
    DataGrid1.Columns[0].ItemStyle.Width=Unit.Pixel(100);
    }

    Actually, the datagrid control will render as <table> html tag.After
    setting its column width, .Net will add "width" attribute to all the <td>
    in that column.(You can determine this through view html source in page)

    Note: If your column's width is very small, IE will wrap the text in all
    the cells(<td> tags) in that column, so the whole datagrid height
    increased. But IE will not wrap a single word, so there are a minimal size
    for the width to take effect.(The minimal size is the longest word in that
    column)
    For example, if I set a column width to 5px, which is smaller than most of
    the words, then the text in <td> will like this:
    //First <td>
    Public
    Relations
    Manager

    //Second <td>
    Sales
    Representative

    //Third <td>
    Operations
    Manager

    So this column's width will be the width of word "Representative".(Because
    it is the longest word in that column). If you view the source, you will
    see that all the <td> still have width attribute with value 10px. So this
    is the default behavior of IE browser not Asp.net.

    Hope this make sense to you.
    =================================================================
    Please apply my suggestion above and let me know if it helps resolve your
    problem.

    Thank you for your patience and cooperation. If you have any questions or
    concerns, please feel free to post it in the group. I am standing by to be
    of assistance.
    Hope you have a nice experience in Microsoft Newsgroup!

    Best regards,
    Jeffrey Tan
    Microsoft Online Partner Support
    Get Secure! - www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
     
    Jeffrey Tan[MSFT], Jan 20, 2004
    #3
    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. Nedu N

    adjusting datagrid column width

    Nedu N, Jan 19, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,238
    Jeffrey Tan[MSFT]
    Jan 20, 2004
  2. backer
    Replies:
    0
    Views:
    755
    backer
    Mar 12, 2007
  3. backer
    Replies:
    0
    Views:
    397
    backer
    Mar 12, 2007
  4. backer
    Replies:
    0
    Views:
    610
    backer
    Mar 12, 2007
  5. =?Utf-8?B?Vmlua2k=?=

    adjusting column width of exported gridview in excel

    =?Utf-8?B?Vmlua2k=?=, Oct 26, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    527
    =?Utf-8?B?Vmlua2k=?=
    Oct 26, 2007
Loading...

Share This Page