N
news.microsoft.com
Hello,
Here is the problem. I have created an array of list items and I am adding
them to many DropDownList controls.
--------------The Code -------------------
Dim liArray(5) As ListItem
liArray(0) = New ListItem("First", "1")
liArray(1) = New ListItem("Second", "2")
liArray(2) = New ListItem("Third", "3")
liArray(3) = New ListItem("Fourth", "4")
liArray(4) = New ListItem("Last", "8")
DropDownList1.Items.AddRange(liArray) <--- Fails here!!
DropDownList2.Items.AddRange(liArray)
--------------------------------------------
When I debug I check the following.
? isNothing(liArray)
False
? isNothing(DropDownList1)
False
? isNothing(DropDownList2)
False
--------- Server Error ---------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
Source Error:
Line 1068: liArray(3) = New ListItem("Fourth", "4")
Line 1069: liArray(4) = New ListItem("Last", "8")
Line 1070: DropDownList1.Items.AddRange(liArray)
Line 1071: DropDownList2.Items.AddRange(liArray)
Line 1072:
Why is this happening? The code is simple.
Thanks,
B
Here is the problem. I have created an array of list items and I am adding
them to many DropDownList controls.
--------------The Code -------------------
Dim liArray(5) As ListItem
liArray(0) = New ListItem("First", "1")
liArray(1) = New ListItem("Second", "2")
liArray(2) = New ListItem("Third", "3")
liArray(3) = New ListItem("Fourth", "4")
liArray(4) = New ListItem("Last", "8")
DropDownList1.Items.AddRange(liArray) <--- Fails here!!
DropDownList2.Items.AddRange(liArray)
--------------------------------------------
When I debug I check the following.
? isNothing(liArray)
False
? isNothing(DropDownList1)
False
? isNothing(DropDownList2)
False
--------- Server Error ---------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
Source Error:
Line 1068: liArray(3) = New ListItem("Fourth", "4")
Line 1069: liArray(4) = New ListItem("Last", "8")
Line 1070: DropDownList1.Items.AddRange(liArray)
Line 1071: DropDownList2.Items.AddRange(liArray)
Line 1072:
Why is this happening? The code is simple.
Thanks,
B