I've got a ASP.NET application that has 100 dropdown list boxes.. I need to populate all 100 dropdown list boxes with the same data that I'm extracting from a MS Access database..
The code I'm using is:
The dropdown list boxes are names Item1PartNumberDropDownList to Item 100PartNumberDropDownList...
I get the following error:
Line 39 is CType(Me.Page.FindControl("Item" & DropDownListCount.ToString & "PartNumberDropDownList"), DropDownList).Items.Add(DropDownListData)
Can anyone assist with this please?
The code I'm using is:
VB.NET:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
objCmdPartNumber = New OleDbCommand("SELECT ProductPartNumber, ProductDescription FROM ProductHierarchy ORDER BY ProductPartNumber ASC", objConPartNumber)
objConPartNumber.Open()
objDRPartNumber = objCmdPartNumber.ExecuteReader
Dim DropDownListData As String = ""
Dim DropDownListCount As Integer = 0
Dim DropDownListCurrent As String = ""
While objDRPartNumber.Read()
DropDownListData = ""
If Len(objDRPartNumber("ProductDescription")) <= 70 Then
DropDownListData = objDRPartNumber("ProductPartNumber") & " - " & objDRPartNumber("ProductDescription")
Else
DropDownListData = objDRPartNumber("ProductPartNumber") & " - " & Mid(objDRPartNumber("ProductDescription"), 1, 70) & "...."
End If
For DropDownListCount = 1 To 100
CType(Me.Page.FindControl("Item" & DropDownListCount.ToString & "PartNumberDropDownList"), DropDownList).Items.Add(DropDownListData)
Next
End While
objConPartNumber.Close()
End Sub
The dropdown list boxes are names Item1PartNumberDropDownList to Item 100PartNumberDropDownList...
I get the following error:
System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="App_Web_l09mpxf_"
StackTrace:
at ContentListCreate.Page_Load(Object sender, EventArgs e) in C:\ESWCIMS\ContentListCreate.aspx.vb:line 39
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:
Line 39 is CType(Me.Page.FindControl("Item" & DropDownListCount.ToString & "PartNumberDropDownList"), DropDownList).Items.Add(DropDownListData)
Can anyone assist with this please?