all groups > asp.net datagrid control > september 2004 >
You're in the

asp.net datagrid control

group:

Headings in the DataGrid Web Control


Headings in the DataGrid Web Control Alan Lambert
9/29/2004 2:39:02 PM
asp.net datagrid control: 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.

Re: Headings in the DataGrid Web Control Alan Lambert
9/29/2004 3:55:03 PM
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?


[quoted text, click to view]
Re: Headings in the DataGrid Web Control Alvin Bruney [MVP]
9/29/2004 4:58:25 PM
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
[quoted text, click to view]

Re: Headings in the DataGrid Web Control Alvin Bruney [MVP]
9/29/2004 6:15:36 PM
[quoted text, click to view]

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
[quoted text, click to view]

Re: Headings in the DataGrid Web Control Alan Lambert
9/30/2004 1:29:05 AM
Ah, now I get it!

Many thanks for the advice.

Alan

[quoted text, click to view]
Re: Headings in the DataGrid Web Control Mark Rae
9/30/2004 8:08:03 AM
[quoted text, click to view]

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

Re: Headings in the DataGrid Web Control Alvin Bruney [MVP]
9/30/2004 9:23:21 AM
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[i][0].tostring();
rowOne[1] = dataset2.tables[0].rows[i][1].tostring();
dsTemp.Tables[0].Rows.Add(rowOne);


DataRow rowTwo = dataset1.tables[0].rows.NewRow();
rowTwo[0] = dataset1.tables[0].rows[i][2].tostring();
rowTwo[1] = dataset2.tables[0].rows[i][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
[quoted text, click to view]

Re: Headings in the DataGrid Web Control Mark Rae
9/30/2004 3:30:21 PM
[quoted text, click to view]

Thanks for the advice - I'll give it a go...

AddThis Social Bookmark Button