Can I merge adjacent cells in a .NET 2.0 Gridview control?

Discussion in 'ASP .Net Web Controls' started by Andrew Shaw, Feb 21, 2008.

  1. Andrew Shaw

    Andrew Shaw Guest

    I have a gridview control that is returning rows where for 1 column the
    value is usually the same. Occasionally the last couple of rows will
    have a different value for this column. (2 unique values total). Instead
    of displaying the same value in this column for every row, I'd like to
    be able to merge all the identical values into one cell, similarly to
    how I could do it in Excel.

    I realise that this may be going way beyond what the Gridview is
    supposed to do and if its not possible to do easily then that's fine,
    I'll look at other options of providing some visial indication of a
    change in that value, but I'm just wondering if this can easily be done
    with the gridview (since its spot on for everything else I need it for!)

    Here's a rough diagram of the sort of thing I'm looking for:

    Col 1 | Col 2 | Col 3 | Col 4 |
    ------+-------+-------+-------+
    | Val 2 | Val 3 | Val 4 |
    +-------+-------+-------+
    Val 1 | Val 5 | Val 6 | Val 7 |
    +-------+-------+-------+
    | Val 8 | Val 9 | Val A |
    ------+-------+-------+-------+
    Val B | Val C | Val D | Val E |

    The above diagram probably won't look too good if your reader doesn't
    have a monospaced font - sorry for that!
     
    Andrew Shaw, Feb 21, 2008
    #1
    1. Advertising

  2. Andrew Shaw

    Riki Guest

    Andrew Shaw wrote:
    > I have a gridview control that is returning rows where for 1 column
    > the value is usually the same. Occasionally the last couple of rows
    > will have a different value for this column. (2 unique values total).
    > Instead of displaying the same value in this column for every row,
    > I'd like to be able to merge all the identical values into one cell,
    > similarly to how I could do it in Excel.
    >
    > I realise that this may be going way beyond what the Gridview is
    > supposed to do and if its not possible to do easily then that's fine,
    > I'll look at other options of providing some visial indication of a
    > change in that value, but I'm just wondering if this can easily be
    > done with the gridview (since its spot on for everything else I need
    > it for!)
    > Here's a rough diagram of the sort of thing I'm looking for:
    >
    > Col 1 | Col 2 | Col 3 | Col 4 |
    > ------+-------+-------+-------+
    > | Val 2 | Val 3 | Val 4 |
    > +-------+-------+-------+
    > Val 1 | Val 5 | Val 6 | Val 7 |
    > +-------+-------+-------+
    > | Val 8 | Val 9 | Val A |
    > ------+-------+-------+-------+
    > Val B | Val C | Val D | Val E |
    >
    > The above diagram probably won't look too good if your reader doesn't
    > have a monospaced font - sorry for that!


    What you want is called grouping.

    Search Google for "gridview grouping", that will give you some samples how
    to do it.
    Mostly, it is done just by blanking out the doubles, not by merging the
    cells.

    Merging cells can be done easily, I think. Gridview cells inherit from
    TableCell controls, which have a RowSpan property that you can set.
    This also requires removing the cells below the one with the extended
    rowspan (row.Cells.RemoveAt(0) or something).

    Jos
     
    Riki, Feb 23, 2008
    #2
    1. Advertising

  3. Andrew Shaw

    Andrew Shaw Guest

    Riki wrote:
    > Andrew Shaw wrote:
    >> I have a gridview control that is returning rows where for 1 column
    >> the value is usually the same. Occasionally the last couple of rows
    >> will have a different value for this column. (2 unique values total).
    >> Instead of displaying the same value in this column for every row,
    >> I'd like to be able to merge all the identical values into one cell,
    >> similarly to how I could do it in Excel.
    >>
    >> I realise that this may be going way beyond what the Gridview is
    >> supposed to do and if its not possible to do easily then that's fine,
    >> I'll look at other options of providing some visial indication of a
    >> change in that value, but I'm just wondering if this can easily be
    >> done with the gridview (since its spot on for everything else I need
    >> it for!)
    >> Here's a rough diagram of the sort of thing I'm looking for:
    >>
    >> Col 1 | Col 2 | Col 3 | Col 4 |
    >> ------+-------+-------+-------+
    >> | Val 2 | Val 3 | Val 4 |
    >> +-------+-------+-------+
    >> Val 1 | Val 5 | Val 6 | Val 7 |
    >> +-------+-------+-------+
    >> | Val 8 | Val 9 | Val A |
    >> ------+-------+-------+-------+
    >> Val B | Val C | Val D | Val E |
    >>
    >> The above diagram probably won't look too good if your reader doesn't
    >> have a monospaced font - sorry for that!

    >
    > What you want is called grouping.
    >
    > Search Google for "gridview grouping", that will give you some samples how
    > to do it.
    > Mostly, it is done just by blanking out the doubles, not by merging the
    > cells.
    >
    > Merging cells can be done easily, I think. Gridview cells inherit from
    > TableCell controls, which have a RowSpan property that you can set.
    > This also requires removing the cells below the one with the extended
    > rowspan (row.Cells.RemoveAt(0) or something).
    >
    > Jos
    >
    >


    Excellent - thanks very much for the tips - I'll go poke Google now!

    Andrew
     
    Andrew Shaw, Feb 24, 2008
    #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. Mark Goldin

    Merge cells

    Mark Goldin, Jun 24, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    432
    Mark Goldin
    Jun 24, 2004
  2. Phil Winstanley [Microsoft MVP ASP.NET]

    Re: Merge cells

    Phil Winstanley [Microsoft MVP ASP.NET], Jun 24, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    408
    Mark Goldin
    Jun 25, 2004
  3. Replies:
    0
    Views:
    538
  4. Joel Finkel

    Cells[].Text or Cells[].Controls[0]

    Joel Finkel, Sep 1, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    319
    Joel Finkel
    Sep 1, 2003
  5. Michael Schmarck

    Spreadsheet Excel: How to merge cells?

    Michael Schmarck, Jan 29, 2008, in forum: Ruby
    Replies:
    1
    Views:
    126
    melampus
    Jan 29, 2008
Loading...

Share This Page