cfisher440
Well-known member
- Joined
- Oct 11, 2005
- Messages
- 73
- Programming Experience
- 1-3
I am basically converting a VB .NET app to an ASP .NET app
I have three listboxes. Selecting one item from on list box, will populate another listbox with items.
Example - listbox 1 has values Car and boat. If you select car, the next list box has items "Ford" and "Honda"
In VB.net the code looks something like this
In asp.net when I do this I get a blue squiggly line under
"if box1.SelectedItem = "Car" then"
It says Operator '=' is not defined for types 'System.Web.UI.Webcontrols.ListItem' and 'String'. Use Is operator to compare two reference types.
I used the 'Is' operator but it's not making the next list box visible
when I use if box1.SelectedIndex = 0 then
I do not recieve a blue squiggly line. But when I run the app and select Car nothing happens. Nothing shows up in box2
any questions / comments / ideas / solutions would be appreciated
I have three listboxes. Selecting one item from on list box, will populate another listbox with items.
Example - listbox 1 has values Car and boat. If you select car, the next list box has items "Ford" and "Honda"
In VB.net the code looks something like this
VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Page_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Load[/SIZE]
[SIZE=2][COLOR=#008000]'Put user code to initialize the page here[/COLOR][/SIZE]
[SIZE=2]box1.Items.Add("Car")[/SIZE]
[SIZE=2]box1.Items.Add("Boat")[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] box1_SelectedIndexChanged([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] box1.SelectedIndexChanged[/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] box1.SelectedItem = "Car" [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]box2.Visible = [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE]
[SIZE=2]box2.Items.Clear()[/SIZE]
[SIZE=2]box2.Items.Add("Ford")[/SIZE]
[SIZE=2]box2.Items.Add("Honda")[/SIZE]
[SIZE=2][COLOR=#0000ff]ElseIf[/COLOR][/SIZE][SIZE=2] box1.SelectedValue Is [/SIZE][SIZE=2]"Boat" [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]box2.Visible = [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE]
[SIZE=2]box2.Items.Clear()[/SIZE]
[SIZE=2]box2.Items.Add("Small")[/SIZE]
[SIZE=2]box2.Items.Add("Big")[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
In asp.net when I do this I get a blue squiggly line under
"if box1.SelectedItem = "Car" then"
It says Operator '=' is not defined for types 'System.Web.UI.Webcontrols.ListItem' and 'String'. Use Is operator to compare two reference types.
I used the 'Is' operator but it's not making the next list box visible
when I use if box1.SelectedIndex = 0 then
I do not recieve a blue squiggly line. But when I run the app and select Car nothing happens. Nothing shows up in box2
any questions / comments / ideas / solutions would be appreciated
Last edited: