Link to home
Start Free TrialLog in
Avatar of NateDizzle
NateDizzle

asked on

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
Avatar of tusharashah
tusharashah

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

-tushar
ASKER CERTIFIED SOLUTION
Avatar of tusharashah
tusharashah

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NateDizzle

ASKER

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?
- 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.
wow I didn't even see the comment added by tusharashah while I wrote all that garble...I'll give it a try, thanks.
Wicked thanks!!
Nice to have you going NateDizle :)

-tushar