开发者

How to declare a datasource in VB.NET?

开发者 https://www.devze.com 2023-03-14 21:12 出处:网络
I wrote an ASPX file in VB.NET.Originally this file ran successfully but after adding one additional parameter it now fails on \"Name \'peType\' is not declared\".

I wrote an ASPX file in VB.NET. Originally this file ran successfully but after adding one additional parameter it now fails on "Name 'peType' is not declared".

This error does not make sense to me though because I have similar parameter, 'dType', which it does not error on. What is the cause of this error?

Here is some of my ASPX code file:

    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>

But now my error is: Object reference n开发者_C百科ot set to an instance of an object


You missed setting the DataTextField and DataValueField property, when you tried to bind DataSource to your Dropdownlist, so set as follows:

peType.DataSource = arrPEType
peType.DataTextField = "DisplayColumnName"
peType.DataValueField = "ValueColumnName"
peType.DataBind()
0

精彩评论

暂无评论...
验证码 换一张
取 消