How to align items vertically on a datagrid

Discussion in 'ASP .Net' started by Julia B, Jan 29, 2008.

  1. Julia B

    Julia B Guest

    Hi, I'm working with .net version 1.1.

    I've got a datagrid on a webform that my users want a fixed height, which is
    fine. It can contain up to 10 records. If there are 10 records then it's fine
    and looks very nice. However if there is only 1 record (or just a few) then
    it looks daft, because the records aren't vertically aligned at the top.

    I can't find a vertical alignment property for a datagrid. Is there a way of
    working this so that the records will always be placed at the top?

    Thanks
    Juia
     
    Julia B, Jan 29, 2008
    #1
    1. Advertising

  2. Don't set any height attribute for the grid and it will align the rows
    nicely. Instead, put the grid in a <div> and set the height for the div. You
    can create an impression that the grid fills up the whole height of the
    <div> even if it has less than 10 records by setting the same background
    color for the grid and the <div>.

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Julia B" <> wrote in message
    news:...
    > Hi, I'm working with .net version 1.1.
    >
    > I've got a datagrid on a webform that my users want a fixed height, which
    > is
    > fine. It can contain up to 10 records. If there are 10 records then it's
    > fine
    > and looks very nice. However if there is only 1 record (or just a few)
    > then
    > it looks daft, because the records aren't vertically aligned at the top.
    >
    > I can't find a vertical alignment property for a datagrid. Is there a way
    > of
    > working this so that the records will always be placed at the top?
    >
    > Thanks
    > Juia
     
    Eliyahu Goldin, Jan 30, 2008
    #2
    1. Advertising

  3. Julia B

    Julia B Guest

    Thanks Eliyahu, however that's not going to work, I don't think. I've already
    got it in a layout which has a set height, however the datagrid itself,
    although having the same colour background, has a border round the edge and
    vertical column borders, which the users require. This means that the actual
    grid size would be visible.

    Julia

    "Eliyahu Goldin" wrote:

    > Don't set any height attribute for the grid and it will align the rows
    > nicely. Instead, put the grid in a <div> and set the height for the div. You
    > can create an impression that the grid fills up the whole height of the
    > <div> even if it has less than 10 records by setting the same background
    > color for the grid and the <div>.
    >
    > --
    > Eliyahu Goldin,
    > Software Developer
    > Microsoft MVP [ASP.NET]
    > http://msmvps.com/blogs/egoldin
    > http://usableasp.net
    >
    >
    > "Julia B" <> wrote in message
    > news:...
    > > Hi, I'm working with .net version 1.1.
    > >
    > > I've got a datagrid on a webform that my users want a fixed height, which
    > > is
    > > fine. It can contain up to 10 records. If there are 10 records then it's
    > > fine
    > > and looks very nice. However if there is only 1 record (or just a few)
    > > then
    > > it looks daft, because the records aren't vertically aligned at the top.
    > >
    > > I can't find a vertical alignment property for a datagrid. Is there a way
    > > of
    > > working this so that the records will always be placed at the top?
    > >
    > > Thanks
    > > Juia

    >
    >
    >
     
    Julia B, Jan 30, 2008
    #3
  4. Your last resort would be to produce always exactly 10 columns. If you have
    less than 10 data rows, add some empty ones. I would do it on the
    datasource.

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Julia B" <> wrote in message
    news:...
    > Thanks Eliyahu, however that's not going to work, I don't think. I've
    > already
    > got it in a layout which has a set height, however the datagrid itself,
    > although having the same colour background, has a border round the edge
    > and
    > vertical column borders, which the users require. This means that the
    > actual
    > grid size would be visible.
    >
    > Julia
    >
    > "Eliyahu Goldin" wrote:
    >
    >> Don't set any height attribute for the grid and it will align the rows
    >> nicely. Instead, put the grid in a <div> and set the height for the div.
    >> You
    >> can create an impression that the grid fills up the whole height of the
    >> <div> even if it has less than 10 records by setting the same background
    >> color for the grid and the <div>.
    >>
    >> --
    >> Eliyahu Goldin,
    >> Software Developer
    >> Microsoft MVP [ASP.NET]
    >> http://msmvps.com/blogs/egoldin
    >> http://usableasp.net
    >>
    >>
    >> "Julia B" <> wrote in message
    >> news:...
    >> > Hi, I'm working with .net version 1.1.
    >> >
    >> > I've got a datagrid on a webform that my users want a fixed height,
    >> > which
    >> > is
    >> > fine. It can contain up to 10 records. If there are 10 records then
    >> > it's
    >> > fine
    >> > and looks very nice. However if there is only 1 record (or just a few)
    >> > then
    >> > it looks daft, because the records aren't vertically aligned at the
    >> > top.
    >> >
    >> > I can't find a vertical alignment property for a datagrid. Is there a
    >> > way
    >> > of
    >> > working this so that the records will always be placed at the top?
    >> >
    >> > Thanks
    >> > Juia

    >>
    >>
    >>
     
    Eliyahu Goldin, Jan 30, 2008
    #4
  5. How about padding the datagrid to ten items with blanks?

    Andrew
     
    Andrew Morton, Jan 30, 2008
    #5
  6. Julia B

    Julia B Guest

    Good idea and thanks to both of you for that.

    "Andrew Morton" wrote:

    > How about padding the datagrid to ten items with blanks?
    >
    > Andrew
    >
    >
    >
     
    Julia B, Jan 30, 2008
    #6
    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. homer

    div Wont Vertically Align

    homer, Jan 26, 2005, in forum: HTML
    Replies:
    6
    Views:
    4,641
    homer
    Jan 28, 2005
  2. Guybrush Threepwood
    Replies:
    1
    Views:
    468
    Mitja Trampus
    Dec 14, 2005
  3. Replies:
    1
    Views:
    491
  4. Trevor

    CSS Vertically Align Text

    Trevor, Apr 28, 2006, in forum: HTML
    Replies:
    5
    Views:
    9,452
    Barbara de Zoete
    Apr 29, 2006
  5. albert kao
    Replies:
    6
    Views:
    1,363
    Knute Johnson
    Apr 26, 2011
Loading...

Share This Page