0

データを入力するグリッドビューと、ユーザーが選択したレコードの詳細を表示するビュー ボタンがあります。エラーが発生する理由がわかりません:

オブジェクト参照がオブジェクトのインスタンスに設定されていません

2 つのメッセージ ボックスの間に絞り込みました。最初のメッセージ ボックスが表示されますが、2 番目のメッセージ ボックスの前にクラッシュします。どんな提案でも大歓迎です。

    Protected Sub CountAlerts_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles CountAlerts.RowCommand
    If (e.CommandName = "Viewdtails") Then
        Dim index As Integer = Convert.ToInt32(e.CommandArgument)
        Dim NDC, Unit, Cell, DTTM, prod, Query, _startdt, _enddt As String
        Dim DS As DataSet

        NDC = CountAlerts.DataKeys(index).Values("NDC")
        Cell = CountAlerts.DataKeys(index).Values("Cell")
        Unit = CountAlerts.DataKeys(index).Values("Unit")
        DTTM = CountAlerts.DataKeys(index).Values("TimeDate")
        prod = CountAlerts.DataKeys(index).Values("ProductDesc")

        _startdt = If(StartDate.Text = "", DateAdd(DateInterval.Day, -7, System.DateTime.Now).ToShortDateString, StartDate.Text)
        _enddt = If(EndDate.Text = "", System.DateTime.Now.ToShortDateString, EndDate.Text)
        For Each irow As GridViewRow In CycleCountAlerts.Rows
            If irow.Attributes("class") = "highlight" Then
                irow.Attributes.Remove("class")
            End If
        Next

        CountAlerts.Rows(index).Attributes("class") = "highlight"
        Query = " EXEC [Audits].[dbo].[ExceptionDetailsCombined] '" & NDC & "', '" & Cell & "', '" & Unit & "', '" & DTTM & "', '" & Master.CF_User.Viewing & "' "
        DS = SelectQuery(Query)

        If (DS.Tables.Count > 0) Then
            unitbox.Text = DS.Tables(0).Rows(0)("Unit")
            cellbx.Text = DS.Tables(0).Rows(0)("Cell")
            ndcbox.Text = DS.Tables(0).Rows(0)("NDC")
            namebox.Text = DS.Tables(0).Rows(0)("ProductDesc")
            cycdttmbx.Text = DS.Tables(0).Rows(0)("TimeDate")
            cycusr.Text = DS.Tables(0).Rows(0)("CycUser")
            todisp.Text = DS.Tables(0).Rows(0)("TODISPSIZE")
            topkgbox.Text = DS.Tables(0).Rows(0)("TOPKGSIZE")
            toqtybx.Text = DS.Tables(0).Rows(0)("TOQTY")
            FRQTYbx.Text = DS.Tables(0).Rows(0)("FRQTY")
            TextBox2.Text = DS.Tables(0).Rows(0)("ActualQTY")
            cycvarqbox.Text = DS.Tables(0).Rows(0)("CYCLEVARQTY")
            CycleVarPctbx.Text = DS.Tables(0).Rows(0)("CYCLEVARPCT")
            alertrsnbx.Text = DS.Tables(0).Rows(0)("AlertReason")
            combox.Text = DS.Tables(0).Rows(0)("AcceptComment")
            acusr.Text = DS.Tables(0).Rows(0)("AcceptUser")
            acctime.Text = DS.Tables(0).Rows(0)("AcceptTime")
            accstatbx.Text = DS.Tables(0).Rows(0)("AcceptStatus")
            displbl.Text = DS.Tables(0).Rows(0)("Disposition")
        End If

        Query = " EXEC [CF_Audits].[dbo].[CommentTrackerCombined] '" & Master.CF_User.EmployeeID & "', '" & NDC & "', '" & Cell & "', '" & Unit & "', '" & _startdt & "', '" & _enddt & "', '" & Master.CF_User.Viewing & "' "
        DS = SelectQuery(Query)

        If (DS.Tables.Count > 0) Then
            ExceptionHist_GV.DataSource = DS
            ExceptionHist_GV.DataBind()
            ExceptionHist_GV.UseAccessibleHeader = True
            MsgBox("except gv header") 'Runs up to here. 
            ExceptionHist_GV.HeaderRow.TableSection = TableRowSection.TableHeader
            MsgBox("except gv header 2") ' Does not make it to here.
        End If
    End If
End Sub
4

2 に答える 2

0

最も可能性が高いTableRowSection、またはTableRowSection.TableHeaderある/あるNothing

これらが初期化されていることを確認してから使用してください

If MsgBox("except gv header") 
If Not TableRowSection Is Nothing AndAlso Not TableRowSection.TableHeader Is Nothing Then
    ExceptionHist_GV.HeaderRow.TableSection = TableRowSection.TableHeader
Else
    MsgBox "How did we get here?"
End If
MsgBox("except gv header 2") 

初期化していないことを示す「How did we get here」というメッセージが表示された場合

于 2013-05-22T17:06:24.803 に答える
0

オブジェクト指向言語では、オブジェクトを使用する前にインスタンス化する必要があります。

この行の何か:

        ExceptionHist_GV.HeaderRow.TableSection = TableRowSection.TableHeader

newキーワードでインスタンス化されていません。Exceptionスローされた の詳細を確認することで、正確に何を見つけることができます。

またはのいずれExceptionHist_GVかになりますTableRowSection

于 2013-05-22T17:07:24.743 に答える