Confused
Confused

Reputation:

Dropdownlist selecteditem is always the first item despite selection

I have a 4 dropdown boxes. The first 2 will populate the 3rd box. The 3rd box populates the 4th dropdown. When I go to submit, I go get the selectedvalue of the 4th dropdown. For some reason this is always the first value and not the actual selected value. The screen clearly shows another item selected. What may be the problem? Thanks

Upvotes: 1

Views: 6287

Answers (2)

Confused
Confused

Reputation:

No I'm not binding it in the page_Load. The dropdown is only binded whenever the 3rd dropdown selectedvalue changes.

Upvotes: 0

EndangeredMassa
EndangeredMassa

Reputation: 17528

Are you binding the dropdownlist in your page load? Page_Load happens before control events like button submit. So, if you rebind in the page_load before you check the value in the button_submit, it will be reset to the first value in the list.

You can generally avoid this by using the following

Page_Load:

If Not Page.IsPostback() Then
    ''//Bind controls here
End If

If that's not the case, please elaborate on how you bind and use these controls.

Upvotes: 4

Related Questions