Problem with DropDown / ComboBox selecteditem.text return - list is databound

My problem is:

I have databound a dropdown list to an Access databasem the list is populated with the correct values everytime but when I click the submit button and try to get the selectedItem.Text value from that dropdown list the item always defaults to the first item (rather than the one that was actually selected).  This doesn't happen to non-databound dropdown lists and is really a frustratingly simple problem.

Here's the code upon a page refresh/load:

        cnBATT.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings("connectionString")

        DsCountries1.Clear()

        adptCountries.Fill(DsCountries1)

        Me.basedIn.DataBind()
        Me.hqIn.DataBind()

the data members and such have been set in the properties windowm and seem to work since it is populated properly.

When try to get the item text I use:

       text1.Text = Me.basedIn.SelectedItem.Text


extremely frustrated, Nate-Dizzle
NateDizzleAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tusharashahCommented:
Make sure you Bind your DropDownList when IsPostBack is false in Page_Load event:

-tushar
0
tusharashahCommented:
Your code should look like following:
----------------------------------------------------------------------
If Not IsPostBack Then
 cnBATT.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings("connectionString")
 DsCountries1.Clear()
 adptCountries.Fill(DsCountries1)
 Me.basedIn.DataBind()
 Me.hqIn.DataBind()
End If
----------------------------------------------------------------------

If you're binding your DropDownList outside of IsPostBack then when you hit submit it'll get bind again and so the value will be defaulted to the 1st one.

-tushar
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NateDizzleAuthor Commented:
So, I know that the problem is with the page refresh, the selected data is lost during the refresh....not impressed.  Have good method to work around this?
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

NateDizzleAuthor Commented:
- it has to be automatic and the first thing the user will click on is the drop down list....I'm going to try a session variable, I really think this is stupid.
0
NateDizzleAuthor Commented:
wow I didn't even see the comment added by tusharashah while I wrote all that garble...I'll give it a try, thanks.
0
NateDizzleAuthor Commented:
Wicked thanks!!
0
tusharashahCommented:
Nice to have you going NateDizle :)

-tushar
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.