FindByValue() error? Object - Object reference not set to an instance of an object.
Posted on 2004-08-19
I've been coding for the past few days without a hitch and then all of a sudden I run across this problem.
I have a drop down list that gets populated with a dataset that is returned from my business tier.
I've debugged this thing for 5 hours and I still cant figure it out. I've tested the dataset to make sure that it gets populated. I've checked to make sure that the page will load properly if I just bind the Dataset to the Drop Down List. Everything works fine when I'm loading the Dataset, binding it to the Drop Down list, but when I try to do a dropdownlist.items.findbyvalue("12345") (where 12345 is a product # in the drop down list) I get a: "Object reference not set to an instance of an object.".
I've tried hardcoding the value (that I KNOW for a fact is in the DropDownList), I"ve tried dynamically setting it through the Ds, I've tried weird looping options. I've even tried removing the DropDownList and replacing i with a listbox. But again, my dreams and aspirations are cursed by this darn error.
Here is the code i'm using:
Dim DS As New DataSet()
Dim DS2 As New DataSet()
Dim itemNumb As String
m_bus = New business()
DS = m_bus.ReturnAvailableItems()
DS2 = m_bus.ReturnCurrentFeaturedItems()
ddlFeat1.DataSource = DS
ddlFeat1.DataTextField = "ITEMDESC"
ddlFeat1.DataValueField = "item_number"
itemNumb = DS2.Tables(0).Rows(0)("item_number")
ddlFeat1.Items.FindByValue(DS2.Tables(0).Rows(0)("item_number")).Selected = True
The last line is where i get the error.
Does anyone see what might be causing this?