Headings in the DataGrid Web Control

G

Guest

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
 
A

Alvin Bruney [MVP]

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
 
G

Guest

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 said:
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 said:
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
 
A

Alvin Bruney [MVP]

--------- OverAll Heading ---------
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 said:
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 said:
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 said:
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
 
M

Mark Rae

Alvin Bruney said:
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
 
G

Guest

Ah, now I get it!

Many thanks for the advice.

Alan

Alvin Bruney said:
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 said:
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 said:
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
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
 
A

Alvin Bruney [MVP]

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
 
M

Mark Rae

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...
 
R

rosh

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
 
R

rosh

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
 
G

Guest

I have the exact same requirement as posted by Alan.It would be helpful to
see a code snippet of the solution.

thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top