Listbox Help

LaTTicE

Member
Joined
Jun 14, 2004
Messages
11
Programming Experience
1-3
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 http://vbcity.com/forums/faq.asp?fid=15&cat=ListBox%2FComboBox#TID47804. 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:
VB.NET:
 [size=2][color=#0000ff]
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
 
[/color][/size][size=2][color=#0000ff]Next
 
[/color][/size]
The entire .Items.Add() line is underlined blue as well as this one...
VB.NET:
[size=2][color=#008000]
' 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()
 
[/size]
Any Ideas on how to get this to work in ASP.NET using code behind? Any help is greatly appreciated. Thanks in advance
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
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.
 
Top Bottom