Forced Column Widths in a DataGrid?

Discussion in 'ASP .Net' started by =?Utf-8?B?QWxleCBNYWdoZW4=?=, Jun 16, 2006.

  1. Hi. Is there any way to lock down the width of columns in a DataGrid so that
    even if the text in one of the rows of that column is very wide, it just gets
    cut off or something rather than causing the column to get wider?

    The problem is that even if I set the column to wrap text, sometimes a
    single "word" or string is very long without any spaces and therefore doesn't
    wrap but just forces the column wider - and that's not what I want.

    Any ideas?

    PS: I've tried to go the the DataGrid managed group a bunch of times over
    the past month and, at least on the MSDN web site, it always shows as empty
    with no items. That's why I'm posting this here instead of there.

    Thanks!

    Alex
     
    =?Utf-8?B?QWxleCBNYWdoZW4=?=, Jun 16, 2006
    #1
    1. Advertising

  2. if you read CSS documentation, you will see you can set the overflow
    behavior, which is what you want to do.

    -- bruce (sqlwork.com)



    "Alex Maghen" <> wrote in message
    news:...
    > Hi. Is there any way to lock down the width of columns in a DataGrid so
    > that
    > even if the text in one of the rows of that column is very wide, it just
    > gets
    > cut off or something rather than causing the column to get wider?
    >
    > The problem is that even if I set the column to wrap text, sometimes a
    > single "word" or string is very long without any spaces and therefore
    > doesn't
    > wrap but just forces the column wider - and that's not what I want.
    >
    > Any ideas?
    >
    > PS: I've tried to go the the DataGrid managed group a bunch of times over
    > the past month and, at least on the MSDN web site, it always shows as
    > empty
    > with no items. That's why I'm posting this here instead of there.
    >
    > Thanks!
    >
    > Alex
     
    bruce barker \(sqlwork.com\), Jun 16, 2006
    #2
    1. Advertising

  3. =?Utf-8?B?QWxleCBNYWdoZW4=?=

    Greg9Strat Guest

    Yes, you can using something like the following in your control:

    <Columns>
    <asp:BoundField HeaderText="My Header" DataField="MyField"
    HeaderStyle-Width="90px" />
    </Columns>

    That should force the column to be the width that you desire - by using
    a unit measure of "px"... you can also use % to make it adjust to a
    percentage of the window width...
     
    Greg9Strat, Jun 16, 2006
    #3
  4. Hi Alex,

    Thank you for your post.

    You may need to set the table-layout to 'fixed' to make sure fixed width
    column working. For example:

    protected void Page_Load(object sender, EventArgs e)
    {
    ArrayList ar = new ArrayList();
    ar.Add("ReallylonglinewithNoSpacesAtAll!!!!!!!!!! and
    anotherverylonglinelonglinelongline");
    grid1.DataSource = ar;
    grid1.DataBind();
    grid1.Style.Add("table-layout", "fixed");
    }

    protected void grid1_ItemDataBound(object sender, DataGridItemEventArgs
    e)
    {
    //e.Item.Cells[0].Text = "<nobr>" + e.Item.Cells[0].Text +
    "</nobr>";
    e.Item.Cells[0].Attributes.Add("WIDTH", "75px");
    e.Item.Cells[0].Attributes.Add("onmouseover",
    "this.title=this.innerText;");
    }

    This will show a table cell that has 3 lines but the two long words gets
    clipped. If you don't want it gets wrapped, uncomment the first statement
    in ItemDataBound and only the first word gets shown and clipped.


    Regards,
    Walter Wang
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Jun 20, 2006
    #4
    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. wh1974
    Replies:
    1
    Views:
    1,581
    =?Utf-8?B?RmVybmFuZG8gSHVudGg=?=
    Jan 11, 2005
  2. =?Utf-8?B?RWxtZXI=?=

    Datagrid column widths in edit mode

    =?Utf-8?B?RWxtZXI=?=, Apr 8, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    2,437
    =?Utf-8?B?RWxtZXI=?=
    Apr 19, 2005
  3. vpravin
    Replies:
    5
    Views:
    428
  4. Jonathan
    Replies:
    1
    Views:
    710
    David Wier
    Feb 18, 2008
  5. Davef

    Datagrid column widths

    Davef, Oct 28, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    144
    John Soulis [MSFT]
    Oct 28, 2003
Loading...

Share This Page