Hi Phillip,
Ok now I have 2 header rows using the example off the link you provided. I
now have my header row as the second row and my new header row as the first.
New problem: It's as if the 2 header rows are a seperate entity from my data
rows because the columns don't mate up. In my custom headerrow, I set
cell(0).colspan = 2, it spans the 2 columns of the next row (which is my
original headers), but not my datarows. header row col1 is of a different
width than datarow col1. I have (laborously) set the width of every column in
the custom rows to match what I set
the datarows cols to be,taking padding into account, but still different. To
be sure, I wrapped it all in a div with a width greater than my gridview and
set all wrapping to false. I just want an extra header row at top to span
some columns of the original header row and have it still behave just like a
normal gridview. I even tried foregoing this and created a table above the
grid to match and all worked well, that is until I went to print a report.
This produced the same alignment issue. Please help.
Thanks
Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
If e.Row.RowType = DataControlRowType.Header Then
Dim grvrow As GridViewRow = e.Row
Dim tbl As Table = New Table()
Dim row As TableRow = New TableRow
Dim row2 As TableRow = New TableRow()
Dim deletecell As TableCell
Dim aTD(grvrow.Cells.Count - 1) As TableCell
grvrow.Cells.CopyTo(aTD, 0) 'my headers copied to aTD
grvrow.Cells.Clear() ' Original row cleared
row.Cells.AddRange(aTD) ' my headers go from aTD to row
deletecell = row.Cells(row.Cells.Count - 1)
'removes my select header, which is not visible
row.Cells.Remove(deletecell)
tbl.Rows.Add(row)
'second row
row2 = New TableRow()
Dim cell As TableCell = New TableCell()
Dim cell2 As TableCell = New TableCell()
Dim cell3 As TableCell = New TableCell()
Dim cell4 As TableCell = New TableCell()
Dim cell5 As TableCell = New TableCell()
cell.ColumnSpan = 2
row2.Cells.Add(cell)
cell.Text = "Employee Info"
'cell.Width = 181
cell.CssClass = "Header"
cell.Style.Add("border-right-width", "1px")
cell.Style.Add("border-right-color", "black")
cell.Style.Add("border-right-style", "solid")
cell2.ColumnSpan = 5
row2.Cells.Add(cell2)
cell2.Text = "Troubles"
cell2.CssClass = "Header"
cell2.Style.Add("border-right-width", "1px")
cell2.Style.Add("border-right-color", "black")
cell2.Style.Add("border-right-style", "solid")
cell3.ColumnSpan = 4
row2.Cells.Add(cell3)
cell3.Text = "Service Orders"
cell3.CssClass = "Header"
cell3.BorderColor = System.Drawing.Color.Black
cell3.Style.Add("border-right-width", "1px")
cell3.Style.Add("border-right-color", "black")
cell3.Style.Add("border-right-style", "solid")
cell4.ColumnSpan = 2
row2.Cells.Add(cell4)
cell4.Text = "Work Requests"
cell4.CssClass = "Header"
cell4.Style.Add("border-right-width", "1px")
cell4.Style.Add("border-right-color", "black")
cell4.Style.Add("border-right-style", "solid")
cell5.ColumnSpan = 2
row2.Cells.Add(cell5)
cell5.Text = "PRs"
cell5.CssClass = "Header"
cell5.BorderColor = System.Drawing.Color.Black
For Each cell In row2.Cells
cell.Font.Size = 11
Next
tbl.Rows.Add(row2)
'create a new cell within the gridview row
Dim cellGRV As TableCell = New TableCell()
cellGRV.ColumnSpan = aTD.Length
grvrow.Cells.Add(cellGRV)
cellGRV.Controls.Add(tbl)
For Each cell In row.Cells
cell.Font.Size = 8
cell.ForeColor = Drawing.Color.Black
Next
Dim tech As TableCell = row.Cells(0)
tech.Width = Unit.Pixel(139)
Dim ID As TableCell = row.Cells(1)
ID.Width = Unit.Pixel(42)
ID.Style.Add("border-right-width", "1px")
ID.Style.Add("border-right-color", "black")
ID.Style.Add("border-right-style", "solid")
Dim TTs As TableCell = row.Cells(2)
TTs.Width = Unit.Pixel(42)
Dim TThours As TableCell = row.Cells(3)
TThours.Width = Unit.Pixel(64)
Dim TTHPU As TableCell = row.Cells(4)
TTHPU.Width = 54
Dim TTRPT As TableCell = row.Cells(5)
TTRPT.Width = 64
Dim SPUtil As TableCell = row.Cells(6)
SPUtil.Width = 54
SPUtil.Style.Add("border-right-width", "1px")
SPUtil.Style.Add("border-right-color", "black")
SPUtil.Style.Add("border-right-style", "solid")
Dim SOs As TableCell = row.Cells(7)
SOs.Width = 42
Dim SOHours As TableCell = row.Cells(

SOHours.Width = 64
Dim SOHPU As TableCell = row.Cells(9)
SOHPU.Width = 54
Dim IRPT As TableCell = row.Cells(10)
IRPT.Width = 64
IRPT.Style.Add("border-right-width", "1px")
IRPT.Style.Add("border-right-color", "black")
IRPT.Style.Add("border-right-style", "solid")
Dim WR As TableCell = row.Cells(11)
WR.Width = 42
Dim WRHours As TableCell = row.Cells(12)
WRHours.Width = 64
WRHours.Style.Add("border-right-width", "1px")
WRHours.Style.Add("border-right-color", "black")
WRHours.Style.Add("border-right-style", "solid")
Dim PR As TableCell = row.Cells(13)
PR.Width = 42
Dim PRHours As TableCell = row.Cells(14)
PRHours.Width = 64
tbl.Rows.Add(row)
End If
End Sub
"Phillip Williams" wrote:
> Hi Lance,
>
> You are right. My demo runs on the C# code (in which the array was
> initialized using the New keyword and therefore I did not get an error). But
> my VB code would not run (the cause is that I set the array size ot
> Cells.Count instead of Cells.Count-1). The proper syntax should be:
> Dim aTD(grvrow.Cells.Count-1) As TableCell
>
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "pickedaname" wrote:
>
> > Hi Phillip,
> > I am getting a null ref exception when adding the cellarray to the row.
> > Since 'row' is given a value (= New TableRow) I am assuming this is
> > referring to the
> > TableCell array aTD(). When an array is declared, is it also instantiated by
> > default?
> > I cannot instantiate the array as I can the row as there is no 'new' function
> > allowed at that point.
> > row.Cells.AddRange(aTD)
> >
> > "Phillip Williams" wrote:
> >
> > > Actually when I tried it, it did not work on the DataBound event but it
> > > worked on the RowCreated event. You can see the code in this demo:
> > > http://www.webswapp.com/codesamples/...s/default.aspx
> > >
> > > --
> > > HTH,
> > > Phillip Williams
> > > http://www.societopia.net
> > > http://www.webswapp.com
> > >
> > >
> > > "pickedaname" wrote:
> > >
> > > > Hi Phillip,
> > > > I checked out the page you sent, but I don't see what there is to help me with
> > > > my problem. Can you guide me a little?
> > > > Thanks,
> > > > -Lance R.
> > > >
> > > > "Phillip Williams" wrote:
> > > >
> > > > > http://msdn2.microsoft.com/en-us/lib...headerrow.aspx
> > > > > --
> > > > > HTH,
> > > > > Phillip Williams
> > > > > http://www.societopia.net
> > > > > http://www.webswapp.com
> > > > >
> > > > >
> > > > > "pickedaname" wrote:
> > > > >
> > > > > > Hi,
> > > > > > I have a SQL bound gridview with select button and paging enabled.
> > > > > > In the gridviews prerender event, I am inserting another header in row 0.
> > > > > >
> > > > > > Dim table As Table = DirectCast(GridView1.Controls(0), Table)
> > > > > > Dim hrow As GridViewRow = New GridViewRow(0, -1, DataControlRowType.Header,
> > > > > > DataControlRowState.Normal)
> > > > > > Dim th As TableCell = New TableHeaderCell()
> > > > > > th.HorizontalAlign = HorizontalAlign.Center
> > > > > > th.ColumnSpan = 2
> > > > > > th.BackColor = System.Drawing.Color.FromArgb(214, 211, 206)
> > > > > > th.ForeColor = Drawing.Color.Black
> > > > > > th.BorderColor = Drawing.Color.Black
> > > > > > th.BorderWidth = 1
> > > > > > th.Font.Bold = True
> > > > > > th.Text = "Employee"
> > > > > > th.ID = "hdrEmp"
> > > > > > hrow.Cells.Add(th)
> > > > > > table.Rows.AddAt(0, hrow)
> > > > > >
> > > > > > There are other columns added to hrow.Cells above before I add hrow to
> > > > > > table.rows using the same exact coding (different names and colspans) trying
> > > > > > to save space here.
> > > > > > The problem I am having is whenever i click the select button control on any
> > > > > > record,
> > > > > > I lose my pager row and I get an empty row inserted below the header rows.
> > > > > > So if I click another select button, I get yet another blank row inserted
> > > > > > below the headers. I can keep this up until all rows in the grid are blank.
> > > > > > If I load the page and click the pager control to go to page 2 or 3, I don't
> > > > > > get the blank row and I don't lose my pager row, it only happens when select
> > > > > > is clicked. I have nothing going on (yet) when a record is selected, it is
> > > > > > simply selected so there is no other code on the page to respond to
> > > > > > rowselected.
> > > > > > Am I messing up the indexing?
> > > > > > Please Help