ComboBox Text and Value

  • Thread starter Thread starter Jl_G_0
  • Start date Start date
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.
 
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.
 
Back
Top