dropdownlist woes

  • Thread starter Thread starter Wee Bubba
  • Start date Start date
W

Wee Bubba

i have a dropdownlist consisting of titles (Mr,Mrs,etc.). I use the
text property to store a title and the value properties to store a
default gender code. e.g.

Title Default Gender
---- ----------------
Capt M
Col M
Dr U
Mr M
Mrs F
Ms F

lets say i choose 'Mr'. when i do a postback the dropdownlist reverts
back to 'Capt'. My guess is that it has stored the selectedvalue of
'M' in the ViewState so it restores the first value of M it comes
across in the list after postback! Which is Capt. Wrong! How do I get
around this please?
 
You could do

You can grab the int value of the SelectedIndex property when the user first selects the title, then set the SelectedIndex each time there is a post back.

ie,

// class level
int iTitle;

// on SelectedIndexChanged
iTitle = dropDownList.SelectedIndex;

// any other time
dropDownList.SelectedIndex = iTitle;
 
is it possible to do without posting back whenever a user makes a new
selection in the dropdownlist?
 
Back
Top