asp .net combo box

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

I have a drop down list that is databound to a custom collection. When the
page loads it populates the drop down list properly with all the values. I
have the drop down list set to autopost back. In the form load I if the it
is a post back I am able to print the appropriate index of the selected
index for the drop down box. However the combo box is still showing the
first item in the list as being selected no matter which item I actually
selected. What am I doing wrong? Any help would be greatly appreciated

Sincerely
Chris
 
I have a drop down list that is databound to a custom collection. When the
page loads it populates the drop down list properly with all the values. I
have the drop down list set to autopost back. In the form load I if the it
is a post back I am able to print the appropriate index of the selected
index for the drop down box. However the combo box is still showing the
first item in the list as being selected no matter which item I actually
selected. What am I doing wrong? Any help would be greatly appreciated


This should automatically get handled by the ViewState for the Page if automatic
ViewState management is not turned off. If it is, you will have to set the
index of the ComboBox back to the selected item after the postback. Of course,
to do this, you will have to hang on to the selected index after an item is
selected in the ComboBox. You could do something like...

Session["cbIndex"] = yourComboBox.SelectedIndex;

Then on the PostBack, you could do the following:

yourComboBox.SelectedIndex = (int) Session["cbIndex"];
 
Back
Top