• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 429
  • Last Modified:

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
0
NateDizzle
Asked:
NateDizzle
  • 4
  • 3
1 Solution
 
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
 
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now