DropDownList selection not updated

  • Thread starter Thread starter Alex
  • Start date Start date
A

Alex

I have a DropDownList on a form. I filled it with some data from a DataSet.
I can select items.
I also added a button to the form. I added a onClick handler. In the code
behind handler I can retrieve all my other fields from the form (input's).
However the SelectedValue of the DropDown box doesn't update.
In fact, after the add the selection is back to the original selection.

What do I do wrong?
 
This is normal, as the ViewState value is the original setting. You have to
rebind the form to the selected value:

ddlDropDownName.SelectedValue = valuePutInDatabase;

To get valuePutInDatabase, you will

1. If after submit, grab that value and store temporarily in a more "global"
var. Then reset the dropdown using above
2. If when pulling up user record, get value from the DataSet itself.

Hope this makes sense.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
If you are rebinding data to the drop down, then you need to explicitly set
the selectedIndex afterwards in your server side execution code.
 
Well, I didn't expect that the page load handler gets called before running
my button handler.
Is there a way to change this behavior?
 
I made a quick fix with using IsPostBack() in the page load handler.
Still not sure why a page laod handler gets called prior to the button
handler.

Alex said:
Well, I didn't expect that the page load handler gets called before running
my button handler.
Is there a way to change this behavior?
 
Back
Top