Listbox Help


Jun 14, 2004
Programming Experience
I was wondering if anyone could help me with this. I used this class called MyList that I got from this page on a VB.NET project I just finished. It is located at this address I am now developing an identical page, but in ASP.NET and the methods I am trying to use in Code Behind are no longer functioning correctly. Example:
Dim[/color][/size][size=2] i [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Integer
[/color][/size][size=2][color=#0000ff]For[/color][/size][size=2] i = 0 [/size][size=2][color=#0000ff]To[/color][/size][size=2] SQLDSET.Tables(0).Rows.Count() - 1
[/size][size=2][color=#0000ff]	 With[/color][/size][size=2] lsttests
		.Items.Add([/size][size=2][color=#0000ff]New[/color][/size][size=2] Mylist(SQLDSET.Tables(0).Rows(i).ItemArray(0),SQLDSET.Tables(0).Rows(i).ItemArray(1)))
[/size][size=2][color=#0000ff]	 End[/color][/size][size=2][color=#0000ff]With
The entire .Items.Add() line is underlined blue as well as this one...
' Gets the currently selected item's hidden id number in the ListBox.
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] curItem [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]String[/color][/size][size=2] = lsttests.Items(lsttests.SelectedIndex).ItemData()

Any Ideas on how to get this to work in ASP.NET using code behind? Any help is greatly appreciated. Thanks in advance
The example you point out is meant for WinForms since some people believe that the comboBox and listBox controls in VB.NET are missing some of the functionality that was included in VB6 (truth is there is more functionality, they're just a bit different now). Take everything you see on the web with a grain of salt.

The corresponding web controls (dropDownList and listBox) are a a bit different than the WinForm controls. Both have properties called DataTextField and DataValueField.

It seems you have a DataTable; just set the DataSource equal to the DataTable, then set the DataTextField equal to the column you want to display and the DataValueField equal to the column that will supply the value for the comboBox/ListBox item.