web datagrid column width

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nj

    web datagrid column width

    I am trying to set the width of a single column in the datagrid. What is happening is the column seems to stretch to try to accomodate the length of the data contained in it. I want to have it only x number of pixels wide and the data to wrap if necessary. I have tried several things to set the column width but it seems to ignore everything I try.

    I have tried:
    1. Setting the width of the grid to be 50% - still stretches across entire screen.
    2. Executing e.Item.Cells(0) .Width = New Unit(100) in the itemdatabound event- doesn't do anything
    3. Executing e.Item.Cells(0) .Width = New Unit(100) in the itemcreated event- doesn't do anything

    The grid itself is contained in an html table because there are several other grids on the screen and I want to make sure they don't overlap each other.

    Any ideas of what I may be doing wrong or how to make it work... If it will

    Thanks
  • Eliyahu Goldin

    #2
    Re: web datagrid column width

    You don't have full control over column width. The browser considers your
    instructions as recommendations . You can trick it a bit though. If I want a
    column to be as narrow as possible, I set its width to 1px. Then it will get
    the width of the longest first word in the column and the next words will be
    wrapped.

    Eliyahu

    "nj" <nj@discussions .microsoft.com> wrote in message
    news:F0E0FE5F-6468-4024-9670-1EBE56589E3F@mi crosoft.com...[color=blue]
    > I am trying to set the width of a single column in the datagrid. What is[/color]
    happening is the column seems to stretch to try to accomodate the length of
    the data contained in it. I want to have it only x number of pixels wide and
    the data to wrap if necessary. I have tried several things to set the column
    width but it seems to ignore everything I try.[color=blue]
    >
    > I have tried:
    > 1. Setting the width of the grid to be 50% - still stretches across entire[/color]
    screen.[color=blue]
    > 2. Executing e.Item.Cells(0) .Width = New Unit(100) in the itemdatabound[/color]
    event- doesn't do anything[color=blue]
    > 3. Executing e.Item.Cells(0) .Width = New Unit(100) in the itemcreated[/color]
    event- doesn't do anything[color=blue]
    >
    > The grid itself is contained in an html table because there are several[/color]
    other grids on the screen and I want to make sure they don't overlap each
    other.[color=blue]
    >
    > Any ideas of what I may be doing wrong or how to make it work... If it[/color]
    will[color=blue]
    >
    > Thanks[/color]


    Comment

    • S. Justin Gengo

      #3
      Re: web datagrid column width

      nj,

      It may depend on the content in the cell. If that content has no break
      points (a space, hyphen, etc.) that the browser will automatically wrap on
      then that may be the cause. Each browser treats this situation differently.
      The safe thing to do, if it is that the content has no break points, is to
      insert some character that the grid will wrap with.

      --
      Sincerely,

      S. Justin Gengo, MCP
      Web Developer / Programmer



      "Out of chaos comes order."
      Nietzsche
      "nj" <nj@discussions .microsoft.com> wrote in message
      news:F0E0FE5F-6468-4024-9670-1EBE56589E3F@mi crosoft.com...[color=blue]
      > I am trying to set the width of a single column in the datagrid. What is[/color]
      happening is the column seems to stretch to try to accomodate the length of
      the data contained in it. I want to have it only x number of pixels wide and
      the data to wrap if necessary. I have tried several things to set the column
      width but it seems to ignore everything I try.[color=blue]
      >
      > I have tried:
      > 1. Setting the width of the grid to be 50% - still stretches across entire[/color]
      screen.[color=blue]
      > 2. Executing e.Item.Cells(0) .Width = New Unit(100) in the itemdatabound[/color]
      event- doesn't do anything[color=blue]
      > 3. Executing e.Item.Cells(0) .Width = New Unit(100) in the itemcreated[/color]
      event- doesn't do anything[color=blue]
      >
      > The grid itself is contained in an html table because there are several[/color]
      other grids on the screen and I want to make sure they don't overlap each
      other.[color=blue]
      >
      > Any ideas of what I may be doing wrong or how to make it work... If it[/color]
      will[color=blue]
      >
      > Thanks[/color]


      Comment

      Working...