Headings in the DataGrid Web Control

Discussion in 'ASP .Net' started by =?Utf-8?B?QWxhbiBMYW1iZXJ0?=, Sep 29, 2004.

  1. I am writing a web-based reporting tool and using a datagrid to display
    information returned from a database.

    I am displaying column headings from bound columns with no problems but I
    need to have a heading above some of these that spans severla columns e.g.

    --------- OverAll Heading ---------
    Heading1 Heading2 Heading3

    I can't find a way to do this. Is this possible and, if so, how?

    Any help you can give would be very appreciated.

    Many thanks.

    Alan
     
    =?Utf-8?B?QWxhbiBMYW1iZXJ0?=, Sep 29, 2004
    #1
    1. Advertising

  2. have a look at the columnspan property of the cell, it makes the cell
    stretch over the number of columns. you will need to remove the other cells
    before or after you span. additionally you will need to promote row 1 to a
    header. bit of code but not impossible

    --
    Regards,
    Alvin Bruney
    [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    Got tidbits? Get it here... http://tinyurl.com/27cok
    "Alan Lambert" <> wrote in message
    news:...
    >I am writing a web-based reporting tool and using a datagrid to display
    > information returned from a database.
    >
    > I am displaying column headings from bound columns with no problems but I
    > need to have a heading above some of these that spans severla columns e.g.
    >
    > --------- OverAll Heading ---------
    > Heading1 Heading2 Heading3
    >
    > I can't find a way to do this. Is this possible and, if so, how?
    >
    > Any help you can give would be very appreciated.
    >
    > Many thanks.
    >
    > Alan
     
    Alvin Bruney [MVP], Sep 29, 2004
    #2
    1. Advertising

  3. Thanks for the reply.

    Doing the colspan should be no problem but I'm not sure what you mean when
    you say promote row 1 to a header. Wouldn't row 1 contain the first record of
    bound data? What would happen to the dat in this row? Or have I completely
    misunderstood?


    "Alvin Bruney [MVP]" wrote:

    > have a look at the columnspan property of the cell, it makes the cell
    > stretch over the number of columns. you will need to remove the other cells
    > before or after you span. additionally you will need to promote row 1 to a
    > header. bit of code but not impossible
    >
    > --
    > Regards,
    > Alvin Bruney
    > [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    > Got tidbits? Get it here... http://tinyurl.com/27cok
    > "Alan Lambert" <> wrote in message
    > news:...
    > >I am writing a web-based reporting tool and using a datagrid to display
    > > information returned from a database.
    > >
    > > I am displaying column headings from bound columns with no problems but I
    > > need to have a heading above some of these that spans severla columns e.g.
    > >
    > > --------- OverAll Heading ---------
    > > Heading1 Heading2 Heading3
    > >
    > > I can't find a way to do this. Is this possible and, if so, how?
    > >
    > > Any help you can give would be very appreciated.
    > >
    > > Many thanks.
    > >
    > > Alan

    >
    >
    >
     
    =?Utf-8?B?QWxhbiBMYW1iZXJ0?=, Sep 29, 2004
    #3
  4. >> > --------- OverAll Heading ---------
    >> > Heading1 Heading2 Heading3


    according to your diagram, you have one header cell stretched across the
    entire grid over Overall heading -----------. well that is the header cell.

    you still need headers for each column(heading1, heading2, heading3). i was
    suggesting one approach would be to insert an empty row at position 0 into
    your dataset before binding. then you can customize row 0 on the
    itemdatabound to be the actual column headers 1, 2, 3 etc

    --
    Regards,
    Alvin Bruney
    [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    Got tidbits? Get it here... http://tinyurl.com/27cok
    "Alan Lambert" <> wrote in message
    news:...
    > Thanks for the reply.
    >
    > Doing the colspan should be no problem but I'm not sure what you mean when
    > you say promote row 1 to a header. Wouldn't row 1 contain the first record
    > of
    > bound data? What would happen to the dat in this row? Or have I completely
    > misunderstood?
    >
    >
    > "Alvin Bruney [MVP]" wrote:
    >
    >> have a look at the columnspan property of the cell, it makes the cell
    >> stretch over the number of columns. you will need to remove the other
    >> cells
    >> before or after you span. additionally you will need to promote row 1 to
    >> a
    >> header. bit of code but not impossible
    >>
    >> --
    >> Regards,
    >> Alvin Bruney
    >> [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    >> Got tidbits? Get it here... http://tinyurl.com/27cok
    >> "Alan Lambert" <> wrote in message
    >> news:...
    >> >I am writing a web-based reporting tool and using a datagrid to display
    >> > information returned from a database.
    >> >
    >> > I am displaying column headings from bound columns with no problems but
    >> > I
    >> > need to have a heading above some of these that spans severla columns
    >> > e.g.
    >> >
    >> > --------- OverAll Heading ---------
    >> > Heading1 Heading2 Heading3
    >> >
    >> > I can't find a way to do this. Is this possible and, if so, how?
    >> >
    >> > Any help you can give would be very appreciated.
    >> >
    >> > Many thanks.
    >> >
    >> > Alan

    >>
    >>
    >>
     
    Alvin Bruney [MVP], Sep 30, 2004
    #4
  5. =?Utf-8?B?QWxhbiBMYW1iZXJ0?=

    Mark Rae Guest

    "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    news:%23OJJd%...
    > have a look at the columnspan property of the cell, it makes the cell
    > stretch over the number of columns. you will need to remove the other
    > cells before or after you span. additionally you will need to promote row
    > 1 to a header. bit of code but not impossible


    Related to this, is there any way to spread one row from the DataSet across
    two rows in the DataGrid? E.g. if you were going through a data merging
    exercise where you had legacy data in one table and current data in another
    table and you wanted to compare the two? They will both have the same number
    of columns and are joined by a primary key something like:

    SELECT
    l.FirstName, l.Surname, l.Address1, l.Town, l.County, l.Postcode,
    c.FirstName, c.Surname, c.Address1, c.Town, c.County, c.Postcode
    FROM EmployeeLegacy l, EmployeeCurrent c
    WHERE l.EmployeeID = c.EmployeeID

    Ignoring the fact that the above will give duplicate column names (it's just
    an illustration), would it be possible to render it in the DataGrid so that
    each row from the DataSet appeared as two rows in the DataGrid e.g.

    Source FirstName Surname Address1 Town County Postcode
    Legacy Mark Rae 1 High St London NULL SW1A 1AA
    Current Mark T Rae 1 High S London NULL SW1A 1AA
     
    Mark Rae, Sep 30, 2004
    #5
  6. Ah, now I get it!

    Many thanks for the advice.

    Alan

    "Alvin Bruney [MVP]" wrote:

    > >> > --------- OverAll Heading ---------
    > >> > Heading1 Heading2 Heading3

    >
    > according to your diagram, you have one header cell stretched across the
    > entire grid over Overall heading -----------. well that is the header cell.
    >
    > you still need headers for each column(heading1, heading2, heading3). i was
    > suggesting one approach would be to insert an empty row at position 0 into
    > your dataset before binding. then you can customize row 0 on the
    > itemdatabound to be the actual column headers 1, 2, 3 etc
    >
    > --
    > Regards,
    > Alvin Bruney
    > [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    > Got tidbits? Get it here... http://tinyurl.com/27cok
    > "Alan Lambert" <> wrote in message
    > news:...
    > > Thanks for the reply.
    > >
    > > Doing the colspan should be no problem but I'm not sure what you mean when
    > > you say promote row 1 to a header. Wouldn't row 1 contain the first record
    > > of
    > > bound data? What would happen to the dat in this row? Or have I completely
    > > misunderstood?
    > >
    > >
    > > "Alvin Bruney [MVP]" wrote:
    > >
    > >> have a look at the columnspan property of the cell, it makes the cell
    > >> stretch over the number of columns. you will need to remove the other
    > >> cells
    > >> before or after you span. additionally you will need to promote row 1 to
    > >> a
    > >> header. bit of code but not impossible
    > >>
    > >> --
    > >> Regards,
    > >> Alvin Bruney
    > >> [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    > >> Got tidbits? Get it here... http://tinyurl.com/27cok
    > >> "Alan Lambert" <> wrote in message
    > >> news:...
    > >> >I am writing a web-based reporting tool and using a datagrid to display
    > >> > information returned from a database.
    > >> >
    > >> > I am displaying column headings from bound columns with no problems but
    > >> > I
    > >> > need to have a heading above some of these that spans severla columns
    > >> > e.g.
    > >> >
    > >> > --------- OverAll Heading ---------
    > >> > Heading1 Heading2 Heading3
    > >> >
    > >> > I can't find a way to do this. Is this possible and, if so, how?
    > >> >
    > >> > Any help you can give would be very appreciated.
    > >> >
    > >> > Many thanks.
    > >> >
    > >> > Alan
    > >>
    > >>
    > >>

    >
    >
    >
     
    =?Utf-8?B?QWxhbiBMYW1iZXJ0?=, Sep 30, 2004
    #6
  7. one approach is to create a results dataset. then loop thru each row in
    dataset1, find the appropriate information in dataset two and insert two
    rows into the new results dataset. fill the rows as needed with information
    from dataset1 and dataset2

    roughly
    DataSet dsTemp = new DataSet();

    DataTable Tables = new DataTable();

    dsTemp.Tables.Add(Tables);

    for( int i = 0; i < dataset1.tables[0].rows.count; i++)
    {
    DataRow rowOne = dataset1.tables[0].rows.NewRow();

    rowOne[0] = dataset1.tables[0].rows[0].tostring();
    rowOne[1] = dataset2.tables[0].rows[1].tostring();
    dsTemp.Tables[0].Rows.Add(rowOne);


    DataRow rowTwo = dataset1.tables[0].rows.NewRow();
    rowTwo[0] = dataset1.tables[0].rows[2].tostring();
    rowTwo[1] = dataset2.tables[0].rows[3].tostring();
    dsTemp.Tables[0].Rows.Add(rowTwo);

    }

    bind to grid using dsTemp

    --
    Regards,
    Alvin Bruney
    [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    Got tidbits? Get it here... http://tinyurl.com/27cok
    "Mark Rae" <> wrote in message
    news:%...
    > "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    > news:%23OJJd%...
    >> have a look at the columnspan property of the cell, it makes the cell
    >> stretch over the number of columns. you will need to remove the other
    >> cells before or after you span. additionally you will need to promote row
    >> 1 to a header. bit of code but not impossible

    >
    > Related to this, is there any way to spread one row from the DataSet
    > across two rows in the DataGrid? E.g. if you were going through a data
    > merging exercise where you had legacy data in one table and current data
    > in another table and you wanted to compare the two? They will both have
    > the same number of columns and are joined by a primary key something like:
    >
    > SELECT
    > l.FirstName, l.Surname, l.Address1, l.Town, l.County, l.Postcode,
    > c.FirstName, c.Surname, c.Address1, c.Town, c.County, c.Postcode
    > FROM EmployeeLegacy l, EmployeeCurrent c
    > WHERE l.EmployeeID = c.EmployeeID
    >
    > Ignoring the fact that the above will give duplicate column names (it's
    > just an illustration), would it be possible to render it in the DataGrid
    > so that each row from the DataSet appeared as two rows in the DataGrid
    > e.g.
    >
    > Source FirstName Surname Address1 Town County Postcode
    > Legacy Mark Rae 1 High St London NULL SW1A
    > 1AA
    > Current Mark T Rae 1 High S London NULL SW1A
    > 1AA
    >
     
    Alvin Bruney [MVP], Sep 30, 2004
    #7
  8. =?Utf-8?B?QWxhbiBMYW1iZXJ0?=

    Mark Rae Guest

    "Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
    news:%...

    > one approach is to create a results dataset. then loop thru each row in
    > dataset1, find the appropriate information in dataset two and insert two
    > rows into the new results dataset. fill the rows as needed with
    > information from dataset1 and dataset2


    Thanks for the advice - I'll give it a go...
     
    Mark Rae, Sep 30, 2004
    #8
  9. =?Utf-8?B?QWxhbiBMYW1iZXJ0?=

    rosh Guest

    thnkx for the reply
    as per the solution suggested by you I have added a blank row to the
    dataset table before binding it to dataGrid but my requirement is that
    the blank row must be the first row in the dataset coz this will help me
    shifting my headers one row below(from row 0 to row 1)and thus i'll b
    able to use my row 0 to span the 2 columns of my header field.
    Note: i want the "Accounts" column to span my 4'th n 5'th column of the
    header in data grid..
    could you help me out with this....a code snippet will be an added
    advantage for my solution.
    thnkx

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    rosh, Oct 6, 2004
    #9
  10. =?Utf-8?B?QWxhbiBMYW1iZXJ0?=

    rosh Guest

    hi thnkx 4 reply
    can u elaborate more on how do i promote row 1 to a
    header?my header is having the sorting,hyperlink functionality....will i
    not loose that if i try shifting header from row 0 to row 1?i am not
    clear about it.could you pleaz explain it with the help of an example
    code lines?
    waiting for reply.....
    cheers

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    rosh, Oct 6, 2004
    #10
  11. I have the exact same requirement as posted by Alan.It would be helpful to
    see a code snippet of the solution.

    thanks

    "rosh" wrote:

    >
    > hi thnkx 4 reply
    > can u elaborate more on how do i promote row 1 to a
    > header?my header is having the sorting,hyperlink functionality....will i
    > not loose that if i try shifting header from row 0 to row 1?i am not
    > clear about it.could you pleaz explain it with the help of an example
    > code lines?
    > waiting for reply.....
    > cheers
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    >
     
    =?Utf-8?B?Y29vbHRlY2g3Nw==?=, Mar 5, 2006
    #11
    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. Saravana

    Re: Datagrid headings

    Saravana, Jul 22, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    474
    Saravana
    Jul 23, 2003
  2. Tracey
    Replies:
    0
    Views:
    373
    Tracey
    Jul 23, 2003
  3. Bazza Formez
    Replies:
    2
    Views:
    396
    Bazza Formez
    Dec 8, 2004
  4. John
    Replies:
    2
    Views:
    466
  5. Alan Lambert

    Headings in the DataGrid Web Control

    Alan Lambert, Sep 29, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    7
    Views:
    136
    Mark Rae
    Sep 30, 2004
Loading...

Share This Page