SetIndex and dropdownlist errors

N

naija naija

Hi Guys,
I have my .aspx below and i'm using SetIndex with selectedIndex
with DropDownList to retrieve Data from my database!!
My function of SetIndex is as follows:-
Function SetIndex(ByVal TheItem As String)

Dim ItemTypes As ArrayList
Dim i As Integer
For i = 0 To ItemTypes.Count - 1
If TheItem = ItemTypes(i) Then
Return i
End If
Next
End Function

When i compile it using VS.NET it comoiles but when i run it i get error
"Name 'ItemTypes' is not declared"
Do i have to still delcare ItemTypes some how..
Pls help!!

My Asp.Net
------------
<asp:TemplateColumn>
<HeaderTemplate>
Type<br>
<asp:DropDownList id="ItemType" runat="server"
DataSource='<%# ItemTypes %>'/>
</HeaderTemplate>
<ItemTemplate>
<asp:DropDownList id="Dropdownlist1" runat="server"
DataSource='<%# ItemTypes %>'
SelectedIndex='<%# SetIndex(Container.DataItem("ItemType"))
%>'/>
</ItemTemplate>
</asp:TemplateColumn>
 
G

Greg Burns

How bout using code akin to this...

Dim TheItem As String="Some Value"

' select that value in drop downlist
Dim MyListItem As ListItem = ddl.Items.FindByValue(TheItem)
ddl.SelectedIndex = ddl.Items.IndexOf(MyListItem)

HTH,
Greg
 
G

Guest

Thanks for the reply Greg but have:-
ItemTypes = New ArrayList
DBConnection = New SqlConnection("")
DBConnection.Open()
SQLString = "SELECT DISTINCT ItemType FROM products1 ORDER BY
ItemType"
DBCommand = New SqlCommand(SQLString, DBConnection)
DBReader = DBCommand.ExecuteReader()
While DBReader.Read()
ItemTypes.Add(DBReader("ItemType"))
End While
DBReader.Close()
DBConnection.Close()

I'm using VS.Net do i have to declare something using Protected WithEvents ?
Now i get the error:-"System.NullReferenceException: Object reference not
set to an instance of an object."
Saying there is na error on the line:- "For i = 0 To ItemTypes.Count - 1"
Any advice?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top