2011-06-24 2 views
0

J'ai écrit un fichier ASPX dans VB.NET. À l'origine, ce fichier a été exécuté avec succès, mais après l'ajout d'un paramètre supplémentaire, il échoue sur "Référence d'objet non définie sur une instance d'un objet" sur la ligne "peType.DataSource = arrPEType" ci-dessous.VB.NET Référence d'objet non définie sur une instance d'un objet

Cette erreur n'a pas de sens pour moi parce que j'ai un paramètre similaire, 'dType', sur lequel elle ne se trompe pas. Quelle est la cause de cette erreur?

Voici une partie de mon fichier de code ASPX:

Sub Page_Load(Sender as Object, E as EventArgs) 
    If Not IsPostback Then 

     Dim TheMonthDate As Date = DateAdd(DateInterval.Month, -1, Today) 
     calStartDate.SelectedDate = CDate((TheMonthDate.Month) & "/1/" & Year(TheMonthDate)).ToString("MM/dd/yyyy") 
     calEndDate.SelectedDate = GlobalFunctions.GlobalF.MonthLastDate(CDate((TheMonthDate.Month) & "/1/" & Year(TheMonthDate)).ToString("MM/dd/yyyy")) 

     Dim arrType as New ArrayList() 
     Dim arrOrgUnit as New ArrayList() 
     Dim arrPEType as New ArrayList() 
     Dim peType As ListBox 

     arrType.Add("Product and Process") 
     arrType.Add("Product")  
     arrType.Add("Process")    
     dType.DataSource = arrType 
     dType.DataBind() 

     arrPEType.Add("-INC") 
     arrPEType.Add("-NC") 
     arrPEType.Add("-QC") 
     peType.DataSource = arrPEType 
     'peType.DataTextField = "DisplayColumnName" 
     'peType.DataValueField = "ValueColumnName" 
     peType.DataBind() 
... 
     Dim TheType as String 
     Dim TheOrgUnit as String 
     Dim PE_Type as String 

     Select Case dType.SelectedValue 
     Case "Product and Process": 
      TheType = "((SMARTSOLVE.V_QXP_ALL_EXCEPTION.QXP_BASE_EXCEPTION)='PXP_PRODUCT_QXP' Or (SMARTSOLVE.V_QXP_ALL_EXCEPTION.QXP_BASE_EXCEPTION)='PXP_PROCESS_QXP')" 
     Case "Product": 
      TheType = "((SMARTSOLVE.V_QXP_ALL_EXCEPTION.QXP_BASE_EXCEPTION)='PXP_PRODUCT_QXP')" 
     Case "Process": 
      TheType = "((SMARTSOLVE.V_QXP_ALL_EXCEPTION.QXP_BASE_EXCEPTION)='PXP_PROCESS_QXP')" 
     End Select 

     Select Case peType.SelectedValue 
     Case "INC": 
      PE_Type = "substring(a.QXP_EXCEPTION_NO, charindex('-', a.QXP_EXCEPTION_NO)+1, 4)='INC'" 
     Case "NC": 
      PE_Type = "substring(a.QXP_EXCEPTION_NO, charindex('-', a.QXP_EXCEPTION_NO)+1, 4)='NC'" 
     Case "QC": 
      PE_Type = "substring(a.QXP_EXCEPTION_NO, charindex('-', a.QXP_EXCEPTION_NO)+1, 4)='QC'" 
     End Select 
... 
      <td> 
      Product Exception Type: 
      </td> 
      <td> 
      <ASP:DROPDOWNLIST ID="peType" RUNAT="Server" AUTOPOSTBACK="true" /> 
      </td> 

Répondre

2

Vous n'êtes pas instancier votre ListBox, votre déclarant simplement.

Dim peType As ListBox() 

... devrait être ...

Dim peType As New ListBox() 

Bien que l'erreur peut sembler vague, il vous dit exactement le problème. Votre objet, peType, n'est pas défini sur une instance d'un objet.

+0

Oui! C'est ce que j'ai fait! Merci. – user371819

+0

@user De rien –

1

Vous n'avez pas créé l'objet.

Vous avez:

Dim peType As ListBox 

Vous devriez avoir:

Dim peType As new ListBox 

ou être trouver une ListBox existante de votre interface utilisateur.

Questions connexes