Wrox Programmer Forums
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 3rd, 2009, 07:16 AM
Authorized User
 
Join Date: Nov 2005
Posts: 41
Thanks: 6
Thanked 1 Time in 1 Post
Send a message via MSN to RobCarter
Default Adding header Rows

Hi All

Hope you can help.

I have 2 datagrids on a form. I am trying to add headers to each grid so that both grids look like this:

grid 1
------------------------------------------------------------------
| | Monday | Tuesday | Wednesday |
------------------------------------------------------------------
|Ward | Occ | % | Occ | % | Occ | % |
------------------------------------------------------------------
| 1 | 6 | 50 | 4 | 95 | 12 | 100 |
------------------------------------------------------------------

grid 2
------------------------------------------------------------------
| | Monday | Tuesday | Wednesday |
------------------------------------------------------------------
|Ward | thr | % | thr | % | thr | % |
------------------------------------------------------------------
| 1 | 6 | 50 | 4 | 95 | 12 | 100 |
------------------------------------------------------------------

What my code actually does is doubles up the days on the first grid e.g.

grid 1
------------------------------------------------------------------
| | Monday | Tuesday | Wednesday |
------------------------------------------------------------------
| | Monday | Tuesday | Wednesday |
------------------------------------------------------------------
|Ward | Occ | % | Occ | % | Occ | % |
------------------------------------------------------------------
| 1 | 6 | 50 | 4 | 95 | 12 | 100 |
------------------------------------------------------------------

grid2
------------------------------------------------------------------
|Ward | Occ | % | Occ | % | Occ | % |
------------------------------------------------------------------
| 1 | 6 | 50 | 4 | 95 | 12 | 100 |
------------------------------------------------------------------

here is the code for the design:
Code:
<asp:DataGridBorderStyle="Solid"BorderWidth="1"BorderColor="#0066ff"ID="grdOccupRpt"AutoGenerateColumns="false"runat="server"Width="100%">
<AlternatingItemStyleBackColor="#ccffff"Font-Names="tahoma"Font-Size="Small"Width="300px"/><ItemStyleBackColor="#99ccff"Font-Names="tahoma"Font-Size="Small"Width="150px"/>
<HeaderStyleBackColor="#3399ff"Font-Names="tahoma"Font-Size="Small"ForeColor="black"Font-Bold="true"/>
<Columns>
<asp:boundcolumnDataField="ward"HeaderText="Ward">
</asp:boundcolumn>
<asp:boundcolumnDataField="monavail"HeaderText="Avail">
</asp:boundcolumn>
<asp:boundcolumnDataField="monocc"HeaderText="Occ">
</asp:boundcolumn>
<asp:boundcolumnDataField="monoccpt"HeaderText="Perc"DataFormatString="{0:F1}%">
</asp:boundcolumn>
<asp:boundcolumnDataField="tueavail"HeaderText="Avail">
</asp:boundcolumn>
<asp:boundcolumnDataField="tueocc"HeaderText="Occ">
</asp:boundcolumn>
<asp:boundcolumnDataField="tueoccpt"HeaderText="Perc"DataFormatString="{0:F1}%">
</asp:boundcolumn>
<asp:boundcolumnDataField="wedavail"HeaderText="Avail">
</asp:boundcolumn>
<asp:boundcolumnDataField="wedocc"HeaderText="Occ">
</asp:boundcolumn>
<asp:boundcolumnDataField="wedoccpt"HeaderText="Perc"DataFormatString="{0:F1}%">
</asp:boundcolumn>
<asp:boundcolumnDataField="thuavail"HeaderText="Avail">
</asp:boundcolumn>
<asp:boundcolumnDataField="thuocc"HeaderText="Occ">
</asp:boundcolumn>
<asp:boundcolumnDataField="thuoccpt"HeaderText="Perc"DataFormatString="{0:F1}%">
</asp:boundcolumn>
<asp:boundcolumnDataField="friavail"HeaderText="Avail">
</asp:boundcolumn>
<asp:boundcolumnDataField="friocc"HeaderText="Occ">
</asp:boundcolumn>
<asp:boundcolumnDataField="frioccpt"HeaderText="Perc"DataFormatString="{0:F1}%">
</asp:boundcolumn>
<asp:boundcolumnDataField="satavail"HeaderText="Avail">
</asp:boundcolumn>
<asp:boundcolumnDataField="satocc"HeaderText="Occ">
</asp:boundcolumn>
<asp:boundcolumnDataField="satoccpt"HeaderText="Perc"DataFormatString="{0:F1}%">
</asp:boundcolumn>
<asp:boundcolumnDataField="sunavail"HeaderText="Avail">
</asp:boundcolumn>
<asp:boundcolumnDataField="sunocc"HeaderText="Occ">
</asp:boundcolumn>
<asp:boundcolumnDataField="sunoccpt"HeaderText="Perc"DataFormatString="{0:F1}%">
</asp:boundcolumn>
</Columns>
</asp:DataGrid>
<br/>
<br/>
<div>
<h3>
Ward Throughput Report for <% Response.Write(fn_findStartEndDate("sta", Application("strNowdate")))%> and <% Response.Write(fn_findStartEndDate("end", Application("strNowdate")))%>
</h3>
</div>
<br/>
<br/>
<asp:DataGridBorderStyle="Solid"BorderWidth="1"BorderColor="#0066ff"ID="grdThruPutRpt"AutoGenerateColumns="false"runat="server"Width="100%">
<AlternatingItemStyleBackColor="#ccffff"Font-Names="tahoma"Font-Size="Small"Width="300px"/><ItemStyleBackColor="#99ccff"Font-Names="tahoma"Font-Size="Small"Width="150px"/>
<HeaderStyleBackColor="#3399ff"Font-Names="tahoma"Font-Size="Small"ForeColor="black"Font-Bold="true"/>
 
<Columns>
<asp:boundcolumnDataField="ward"HeaderText="Ward">
</asp:boundcolumn>
<asp:boundcolumnDataField="monavail"HeaderText="MonAvail">
</asp:boundcolumn>
<asp:boundcolumnDataField="monthru"HeaderText="Monthru">
</asp:boundcolumn>
<asp:boundcolumnDataField="monpt"HeaderText="MonPT"DataFormatString="{0:F1}%">
</asp:boundcolumn>
<asp:boundcolumnDataField="tueavail"HeaderText="TueAvail">
</asp:boundcolumn>
<asp:boundcolumnDataField="tuethru"HeaderText="Tuethru">
</asp:boundcolumn>
<asp:boundcolumnDataField="tuePT"HeaderText="TuePT"DataFormatString="{0:F1}%">
</asp:boundcolumn>
<asp:boundcolumnDataField="wedavail"HeaderText="WedAvail">
</asp:boundcolumn>
<asp:boundcolumnDataField="wedthru"HeaderText="Wedthru">
</asp:boundcolumn>
<asp:boundcolumnDataField="wedpt"HeaderText="WedPT"DataFormatString="{0:F1}%">
</asp:boundcolumn>
<asp:boundcolumnDataField="thuavail"HeaderText="ThuAvail">
</asp:boundcolumn>
<asp:boundcolumnDataField="thuthru"HeaderText="Thuthru">
</asp:boundcolumn>
<asp:boundcolumnDataField="thupt"HeaderText="ThuPT"DataFormatString="{0:F1}%">
</asp:boundcolumn>
<asp:boundcolumnDataField="friavail"HeaderText="FriAvail">
</asp:boundcolumn>
<asp:boundcolumnDataField="frithru"HeaderText="Frithru">
</asp:boundcolumn>
<asp:boundcolumnDataField="fript"HeaderText="FriPT"DataFormatString="{0:F1}%">
</asp:boundcolumn>
<asp:boundcolumnDataField="satavail"HeaderText="SatAvail">
</asp:boundcolumn>
<asp:boundcolumnDataField="satthru"HeaderText="Satthru">
</asp:boundcolumn>
<asp:boundcolumnDataField="satpt"HeaderText="SatPT"DataFormatString="{0:F1}%">
</asp:boundcolumn>
<asp:boundcolumnDataField="sunavail"HeaderText="SunAvail">
</asp:boundcolumn>
<asp:boundcolumnDataField="sunthru"HeaderText="Sunthru">
</asp:boundcolumn>
<asp:boundcolumnDataField="sunpt"HeaderText="SunPT"DataFormatString="{0:F1}%">
</asp:boundcolumn>
</Columns>
</asp:DataGrid>
and here is the code behind for the itemcreate handlers

Code:
ProtectedSub grdOccupRpt_itemcreated(ByVal sender AsObject, ByVal e As DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Header Then
Dim dgItem As DataGridItem = New DataGridItem(0, 0, ListItemType.Header)
Dim dgCell As TableCell = New TableCell()
dgCell.ColumnSpan = 1
dgCell.HorizontalAlign = HorizontalAlign.Center
dgItem.Cells.Add(dgCell)
dgCell.Text = ""
grdOccupRpt.Controls(0).Controls.AddAt(0, dgItem)
dgCell = New TableCell()
dgCell.ColumnSpan = 3
dgCell.HorizontalAlign = HorizontalAlign.Center
dgItem.Cells.Add(dgCell)
dgCell.Text = "Mon"
grdOccupRpt.Controls(0).Controls.AddAt(0, dgItem)
dgCell = New TableCell()
dgCell.ColumnSpan = 3
dgCell.HorizontalAlign = HorizontalAlign.Center
dgItem.Cells.Add(dgCell)
dgCell.Text = "Tue"
grdOccupRpt.Controls(0).Controls.AddAt(0, dgItem)
dgCell = New TableCell()
dgCell.ColumnSpan = 3
dgCell.HorizontalAlign = HorizontalAlign.Center
dgItem.Cells.Add(dgCell)
dgCell.Text = "Wed"
grdOccupRpt.Controls(0).Controls.AddAt(0, dgItem)
dgCell = New TableCell()
dgCell.ColumnSpan = 3
dgCell.HorizontalAlign = HorizontalAlign.Center
dgItem.Cells.Add(dgCell)
dgCell.Text = "Thu"
grdOccupRpt.Controls(0).Controls.AddAt(0, dgItem)
dgCell = New TableCell()
dgCell.ColumnSpan = 3
dgCell.HorizontalAlign = HorizontalAlign.Center
dgItem.Cells.Add(dgCell)
dgCell.Text = "Fri"
grdOccupRpt.Controls(0).Controls.AddAt(0, dgItem)
dgCell = New TableCell()
dgCell.ColumnSpan = 3
dgCell.HorizontalAlign = HorizontalAlign.Center
dgItem.Cells.Add(dgCell)
dgCell.Text = "sat"
grdOccupRpt.Controls(0).Controls.AddAt(0, dgItem)
dgCell = New TableCell()
dgCell.ColumnSpan = 3
dgCell.HorizontalAlign = HorizontalAlign.Center
dgItem.Cells.Add(dgCell)
dgCell.Text = "sun"
grdOccupRpt.Controls(0).Controls.AddAt(0, dgItem)
EndIf
 
EndSub
ProtectedSub grdThruPutRpt_itemcreated(ByVal sender AsObject, ByVal e As DataGridItemEventArgs) Handles grdThruPutRpt.ItemCreated
If e.Item.ItemType = ListItemType.Header Then
Dim dgItem1 As DataGridItem = New DataGridItem(0, 0, ListItemType.Header)
Dim dgCell1 As TableCell = New TableCell()
dgCell1.ColumnSpan = 1
dgCell1.HorizontalAlign = HorizontalAlign.Center
dgItem1.Cells.Add(dgCell1)
dgCell1.Text = ""
grdOccupRpt.Controls(0).Controls.AddAt(0, dgItem1)
dgCell1 = New TableCell()
dgCell1.ColumnSpan = 3
dgCell1.HorizontalAlign = HorizontalAlign.Center
dgItem1.Cells.Add(dgCell1)
dgCell1.Text = "Mon"
grdOccupRpt.Controls(0).Controls.AddAt(0, dgItem1)
dgCell1 = New TableCell()
dgCell1.ColumnSpan = 3
dgCell1.HorizontalAlign = HorizontalAlign.Center
dgItem1.Cells.Add(dgCell1)
dgCell1.Text = "Tue"
grdOccupRpt.Controls(0).Controls.AddAt(0, dgItem1)
dgCell1 = New TableCell()
dgCell1.ColumnSpan = 3
dgCell1.HorizontalAlign = HorizontalAlign.Center
dgItem1.Cells.Add(dgCell1)
dgCell1.Text = "Wed"
grdOccupRpt.Controls(0).Controls.AddAt(0, dgItem1)
dgCell1 = New TableCell()
dgCell1.ColumnSpan = 3
dgCell1.HorizontalAlign = HorizontalAlign.Center
dgItem1.Cells.Add(dgCell1)
dgCell1.Text = "Thu"
grdOccupRpt.Controls(0).Controls.AddAt(0, dgItem1)
dgCell1 = New TableCell()
dgCell1.ColumnSpan = 3
dgCell1.HorizontalAlign = HorizontalAlign.Center
dgItem1.Cells.Add(dgCell1)
dgCell1.Text = "Fri"
grdOccupRpt.Controls(0).Controls.AddAt(0, dgItem1)
dgCell1 = New TableCell()
dgCell1.ColumnSpan = 3
dgCell1.HorizontalAlign = HorizontalAlign.Center
dgItem1.Cells.Add(dgCell1)
dgCell1.Text = "sat"
grdOccupRpt.Controls(0).Controls.AddAt(0, dgItem1)
dgCell1 = New TableCell()
dgCell1.ColumnSpan = 3
dgCell1.HorizontalAlign = HorizontalAlign.Center
dgItem1.Cells.Add(dgCell1)
dgCell1.Text = "sun"
grdOccupRpt.Controls(0).Controls.AddAt(0, dgItem1)
EndIf
 
EndSub
if anyone can give me any pointers i would appreciate it.

Rob
__________________
Rob Carter
 
Old March 3rd, 2009, 07:23 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

mmm.. did you realize that in grdthruputrpt_itemcreated you copy the text, but never change references?? (you are filling the same grid twice!)
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
 
Old March 3rd, 2009, 07:37 AM
Authorized User
 
Join Date: Nov 2005
Posts: 41
Thanks: 6
Thanked 1 Time in 1 Post
Send a message via MSN to RobCarter
Red face

/facepalm
__________________
Rob Carter
 
Old March 3rd, 2009, 07:38 AM
Authorized User
 
Join Date: Nov 2005
Posts: 41
Thanks: 6
Thanked 1 Time in 1 Post
Send a message via MSN to RobCarter
Default

Thanks by the way.

You have no idea how long it took...
__________________
Rob Carter
 
Old March 3rd, 2009, 07:44 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Thanks button is on the right ;)

LOL
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
The Following User Says Thank You to gbianchi For This Useful Post:
RobCarter (March 3rd, 2009)





Similar Threads
Thread Thread Starter Forum Replies Last Post
adding all the rows to get a total value KeviJay SQL Language 2 May 29th, 2008 03:22 AM
Problem with adding rows to database gule2902 Visual Basic 2005 Basics 4 September 13th, 2007 05:10 PM
adding Header in Word melvik C# 3 March 15th, 2007 07:26 PM
Adding new rows to Datagrid MixedCode General .NET 1 April 10th, 2005 05:00 PM
adding rows to datatable forkhead ADO.NET 2 March 18th, 2004 01:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.