2

フッターにさらに行を追加しようとしていますが、コードでエラーが発生し続けます。私はこれに数日間取り組んでいます。助けてください!

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: Dim footer As GridViewRow = GridView1.FooterRow 行 92: Dim numCells = footer.Cells.Count 行 93: 行 94: Dim newRow As New GridViewRow(footer.RowIndex + 1、-1、footer.RowType、footer.RowState)

4

1 に答える 1

0

この場合、GridView1.FooterRow は null なので、代わりに

Dim footer As GridViewRow = GridView1.FooterRow 

使用する

Dim footer As GridViewRow = e.Row 
于 2012-10-17T06:09:58.393 に答える