DropDownList selection not updated

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?
 
C

Cowboy \(Gregory A. Beamer\)

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!
**********************************************************************
 
P

Peter O'Reilly

If you are rebinding data to the drop down, then you need to explicitly set
the selectedIndex afterwards in your server side execution code.
 
A

Alex

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?
 
A

Alex

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?
 

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,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top