ComboBox Text and Value

J

Jl_G_0

Hey all.
I need to create a ComboBox with some strings on it, but when the user
selects it, I want to have codes for each one of the strings, because
the app is waiting Return in codes (but not index of combobox). I was
thinkin on doing it like this:

cbItem.Text = "Text"
cbItem.Idcode = "Code"

But:
a-) I dont know the 'best' way to create these Item objects and give
properties to it. (Did it with classes, but I hope theres an easier way
to do it)
b-) How would I insert data to the ComboBox using this mode ? I mean, I
could insert the text, but how would I say that the value of this
"Text" is this "Code". I need to change the combobox directly, or does
it have this functionality, if yes i haven't found it ...

So Im asking advice here, as usual only a few tips would help, I can
find more searching if I only had directions...

thanks.
 
S

Siva M

To programmatically add items to DropDowList (there is no 'ComboBox' in
ASP.NET :) ):

DropDownList.Items.Add (new ListItem ("<Text>", "<ID>"));

To fetch the ID of the selected item, DropDownList.SelectedItem.Value

Hey all.
I need to create a ComboBox with some strings on it, but when the user
selects it, I want to have codes for each one of the strings, because
the app is waiting Return in codes (but not index of combobox). I was
thinkin on doing it like this:

cbItem.Text = "Text"
cbItem.Idcode = "Code"

But:
a-) I dont know the 'best' way to create these Item objects and give
properties to it. (Did it with classes, but I hope theres an easier way
to do it)
b-) How would I insert data to the ComboBox using this mode ? I mean, I
could insert the text, but how would I say that the value of this
"Text" is this "Code". I need to change the combobox directly, or does
it have this functionality, if yes i haven't found it ...

So Im asking advice here, as usual only a few tips would help, I can
find more searching if I only had directions...

thanks.
 

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

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top