Reputation:
I have a listbox on my aspx page.
I'd like it to display both the text and associated values (not the index). So if I were to add items like this
Dim this As ListItem = New ListItem("Horse", "2")
Dim that As ListItem = New ListItem("Dog", "3")
me.ListBox.Items.Add(this)
me.ListBox.Items.Add(that)
my listbox would look something like this (please excuse my list of artistic talent):
--------------
|2 Horse |
|3 Dog |
--------------
Is there any way to do this?
Thanks,
Jason
Upvotes: 1
Views: 1492
Reputation: 10452
Sure, why not just combine the text and the value into a variable.
Dim nextItem as ListItem = New ListItem(String.Concat("2", " ", "Horse"), "2")
ListBox.Items.Add(nextItem)
Upvotes: 1
Reputation: 12427
Add the ID as part of the item text?
Dim this As ListItem = New ListItem("2 Horse", "2")
Dim that As ListItem = New ListItem("3 Dog", "3")
Upvotes: 2