Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7164487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:05:00+00:00 2026-05-28T14:05:00+00:00

I am trying to use datasource and bind in my application to set a

  • 0

I am trying to use datasource and bind in my application to set a dropdown list to the results of a query. The dropdownlist populates correctly (shows each different type_name in the set) but later when I use ddltype.selectedvalue – I am always getting the value from the first item in the dataset. Here is the code.

        if ds.hasRows = true
        ddlType.DataValueField = "type_id"
        ddlType.DataTextField = "type_name"
        ddlType.DataSource = ds
        ddlType.DataBind()
        end if

Then later on I use the following code to try to get teh selected value

        Dim typeID = ddlType.SelectedValue

I have ran the query to get the dataset on my SQL server and get the below results – but every time I use the above dim statement, the value is set to 812 even when type 2 is selected. Below is the results from the query that fills the sqldatareader named ds.

type_id : type_name
___________________
812     : type one

813     : type two

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:05:01+00:00Added an answer on May 28, 2026 at 2:05 pm

    Based on the information in your question, I don’t see anything wrong.

    But based on common mistakes people make with this pattern, I am guessing you are probably running ddlType.DataBind() on every postback. So the user clicks a button or something similar to fire the postback, and the DDL is re-bound before your click handler checks the value. Re-binding sets the selectedvalue back to default.

    Edit: Your databinding code in Page_Load should only run once. One way to do this is to wrap the databinding code…

        If Not IsPostBack Then
            If ds.hasRows = True Then
                ddlType.DataValueField = "type_id"
                ddlType.DataTextField = "type_name"
                ddlType.DataSource = ds
                ddlType.DataBind()
            End If
        End If
    

    This will cause the databinding to occur only the first time the page is requested, but not after a button click or other postback action.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying use a set of filter functions to run the appropriate routine,
I am trying to use databinding to bind data to a Silverlight toolkit chart.
When trying to use Flyway application integration to test an OSGi application using Pax
I trying to use Grails Scaffolding to throw a quick CRUD application together around
I'm trying to use a DataTable, filled by a MySqlDataAdapter, which contains a list
I have an external datasource that implements IHierarchicalEnumerable. I'm trying to use that datasource
I'm trying to use an existing database with Grails. My DataSource.groovy starts with this:
i am trying to use this code to bind my asp.net menu control to
i'm trying to create a ObjectDataSource which I can use to bind to a
I'm trying use a BindingList as a DataSource for a ListBox in C# WinForms,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.