Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

merge columns in Gridview footer 1

Status
Not open for further replies.

adugenet

Technical User
Feb 24, 2007
48
US
Is it possible to merge columns in Gridview footer. i have some text in grid footer which I would like to extend for 2 columns.
 
Code:
GridView.FooterRow.Cells[0].ColumnSpan = 2;
should do the trick

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
thank you for your response but the tip you gave me is not working for me...I am trying to merge all the columns 0 to 4 and use it to display a text sub totals here is my code

If (e.Row.RowType = DataControlRowType.Footer) And (gvitems.PageIndex <> gvitems.PageCount - 1) Then

gvitems.FooterRow.Cells(0).ColumnSpan = 2
e.Row.Cells(4).Text = "Sub Totals >>"
e.Row.Cells(5).Text = EstimateTotal.ToString("c")
e.Row.Cells(6).Text = LowBid.ToString("C")
e.Row.Cells(7).Text = Average.ToString("C")
e.Row.Font.Bold = True
e.Row.ForeColor = Drawing.Color.White
e.Row.Cells(5).HorizontalAlign = HorizontalAlign.Left
e.Row.Cells(6).HorizontalAlign = HorizontalAlign.Left
e.Row.Cells(7).HorizontalAlign = HorizontalAlign.Left

End If
 
your code would make the first footer cell 2 columns wide, the 2nd and 3rd footer cells would remain the same. then footer cells 4-7 would have your text/formatting applied. to merge the first 4 cells would require
Code:
gvitems.FooterRow.Cells(0).ColumnSpan = 4
gvitems.FooterRow.Cells.RemoveAt(1)
gvitems.FooterRow.Cells.RemoveAt(2)
gvitems.FooterRow.Cells.RemoveAt(2)

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
thanks you jmeckley for your help...I just did like you suggested to me but i am still getting an error message.here is my code and the error message

System.NullReferenceException: Object reference not set to an instance of an object.

Protected Sub gvitems_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
If e.Row.RowIndex > -1 Then
Dim ItemTotal As Decimal = CType(DataBinder.Eval(e.Row.DataItem, "EngineersEstimate"), Decimal)
Dim LowBd As Decimal = CType(DataBinder.Eval(e.Row.DataItem, "LowBid"), Decimal)
Dim AverageBid As Decimal = CType(DataBinder.Eval(e.Row.DataItem, "Average"), Decimal)
EstimateTotal += ItemTotal
LowBid += LowBd
Average += AverageBid
End If

If (e.Row.RowType = DataControlRowType.Footer) And (gvitems.PageIndex <> gvitems.PageCount - 1) Then

gvitems.FooterRow.Cells(0).ColumnSpan = 4
gvitems.FooterRow.Cells.RemoveAt(1)
gvitems.FooterRow.Cells.RemoveAt(2)
gvitems.FooterRow.Cells.RemoveAt(3)
'e.Row.Cells(4).Text = "Sub Totals >>"
e.Row.Cells(5).Text = EstimateTotal.ToString("c")
e.Row.Cells(6).Text = LowBid.ToString("C")
e.Row.Cells(7).Text = Average.ToString("C")
e.Row.Font.Bold = True
e.Row.ForeColor = Drawing.Color.White
e.Row.Cells(5).HorizontalAlign = HorizontalAlign.Left
e.Row.Cells(6).HorizontalAlign = HorizontalAlign.Left
e.Row.Cells(7).HorizontalAlign = HorizontalAlign.Left

End If
End Sub
 
what line are you receiving this error on? the error states you are trying to access an object that doesn't exist.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
thanks now i figured it out using this...thank you for your help
e.Row.Cells(0).ColumnSpan = 5
 
here is my code just incase someonw wants to use it.Thank you all for the help.
e.Row.Cells(0).ColumnSpan = 5
e.Row.Cells.RemoveAt(1)
e.Row.Cells.RemoveAt(2)
e.Row.Cells.RemoveAt(3)


e.Row.Cells(0).Text = "Sub Totals >>"
e.Row.Cells(1).Text = EstimateTotal.ToString("c")
e.Row.Cells(2).Text = LowBid.ToString("C")
e.Row.Cells(3).Text = Average.ToString("C")
e.Row.Font.Bold = True
e.Row.ForeColor = Drawing.Color.White
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top