我正在尝试向页脚添加更多行,但我的代码不断出现错误。我已经为此工作了几天。请帮忙!
Partial Class Capacity_Plan_Default
Inherits System.Web.UI.Page
Private Property EngTotalQuoteHours As Decimal
Private Property EngTotalUsedHours As Decimal
Private Property column1 As Decimal
Private Property column2 As Decimal
Private Property column3 As Decimal
Private Property CNC_5Axis As Decimal
Private Property CNC_Large As Decimal
Private Property CNC_Small As Decimal
Private Property EDM_Large As Decimal
Private Property EDM_Small As Decimal
Private Property EDM_Trodes As Decimal
Private Property Assy As Decimal
Private Property Polish As Decimal
Private Property Sample As Decimal
Private Property orginalDatatable As Data.DataTable
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim hourRow As GridViewRow = e.Row
If Not IsDBNull(DataBinder.Eval(e.Row.DataItem, "Eng_Quoted_Hrs")) Then
EngTotalQuoteHours += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Eng_Quoted_Hrs"))
End If
If Not IsDBNull(DataBinder.Eval(e.Row.DataItem, "Eng_Used_Hrs")) Then
EngTotalUsedHours += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Eng_Used_Hrs"))
End If
If Not IsDBNull(DataBinder.Eval(e.Row.DataItem, "column1")) Then
column1 += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "column1"))
End If
If Not IsDBNull(DataBinder.Eval(e.Row.DataItem, "column2")) Then
column2 += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "column2"))
End If
If Not IsDBNull(DataBinder.Eval(e.Row.DataItem, "column3")) Then
column3 += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "column3"))
End If
If Not IsDBNull(DataBinder.Eval(e.Row.DataItem, "CNC_5Axis")) Then
CNC_5Axis += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "CNC_5Axis"))
End If
If Not IsDBNull(DataBinder.Eval(e.Row.DataItem, "CNC_Large")) Then
CNC_Large += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "CNC_Large"))
End If
If Not IsDBNull(DataBinder.Eval(e.Row.DataItem, "CNC_Small")) Then
CNC_Small += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "CNC_Small"))
End If
If Not IsDBNull(DataBinder.Eval(e.Row.DataItem, "EDM_Large")) Then
EDM_Large += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "EDM_Large"))
End If
If Not IsDBNull(DataBinder.Eval(e.Row.DataItem, "EDM_Small")) Then
EDM_Small += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "EDM_Small"))
End If
If Not IsDBNull(DataBinder.Eval(e.Row.DataItem, "EDM_Trodes")) Then
EDM_Trodes += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "EDM_Trodes"))
End If
If Not IsDBNull(DataBinder.Eval(e.Row.DataItem, "Assy")) Then
Assy += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Assy"))
End If
If Not IsDBNull(DataBinder.Eval(e.Row.DataItem, "Polish")) Then
Polish += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Polish"))
End If
If Not IsDBNull(DataBinder.Eval(e.Row.DataItem, "Sample")) Then
Sample += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Sample"))
End If
ElseIf e.Row.RowType = DataControlRowType.Footer Then
e.Row.Cells(0).Text = "Total Hours:"
e.Row.Cells(5).Text = EngTotalQuoteHours.ToString
e.Row.Cells(6).Text = EngTotalUsedHours.ToString
e.Row.Cells(7).Text = column1.ToString
e.Row.Cells(8).Text = column2.ToString
e.Row.Cells(9).Text = column3.ToString
e.Row.Cells(10).Text = CNC_5Axis.ToString
e.Row.Cells(11).Text = CNC_Large.ToString
e.Row.Cells(12).Text = CNC_Small.ToString
e.Row.Cells(13).Text = EDM_Large.ToString
e.Row.Cells(14).Text = EDM_Small.ToString
e.Row.Cells(15).Text = EDM_Trodes.ToString
e.Row.Cells(16).Text = Assy.ToString
e.Row.Cells(17).Text = Polish.ToString
e.Row.Cells(18).Text = Sample.ToString
Dim GridView1 As GridView = CType(sender, GridView)
''gets the current footer row to clone
Dim footer As GridViewRow = GridView1.FooterRow
Dim numCells = footer.Cells.Count
Dim newRow As New GridViewRow(footer.RowIndex + 1, -1, footer.RowType, footer.RowState)
''have to add in the right number of cells
''this also copies any styles over from the original footer
For i As Integer = 0 To numCells - 1
Dim emptyCell As New TableCell
emptyCell.ApplyStyle(GridView1.Columns(i).ItemStyle)
newRow.Cells.Add(emptyCell)
Next
newRow.Cells(5).Text = (EngTotalQuoteHours / 46).ToString
''add new row to the gridview table, at the very bottom
CType(GridView1.Controls(0), Table).Rows.Add(newRow)
End If
End Sub
End Class
我得到的错误如下。
你调用的对象是空的。说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:System.NullReferenceException:对象引用未设置为对象的实例。
源错误:
第 90 行:''获取当前页脚行以克隆第 91 行:将页脚调暗为 GridViewRow = GridView1.FooterRow 第 92 行:Dim numCells = footer.Cells.Count 第 93 行:第 94 行:将 newRow 作为新的 GridViewRow(footer.RowIndex + 1、-1、footer.RowType、footer.RowState)