Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

populate dropdownlist with datareader

Posted on 2006-06-29
1
Medium Priority
?
1,242 Views
Last Modified: 2012-08-14
Hi there,

I am having a problem with populating a dropdownlist. The code is as follows :


            myConnection = New SqlConnection ("server=slserver;uid=;pwd=;database=meta_dev")
            SQL$ = ""
            SQL$ = SQL$ & " select      glpd_key      "
            SQL$ = SQL$ & " from        gl_period   "
            myConnection.Open()
            myCommand = New SqlCommand(SQL$, myConnection)
            myDataReader = myCommand.ExecuteReader()
            Me.ddl_glperiod.DataSource = myDataReader
            Me.ddl_glperiod.DataBind()
            'close connection to item_map_gl
            myConnection.Close()

        ddl_glperiod.SelectedIndex = 15
           
When the page load - it populates the dropdownlist with System.Data.Com.... If i debug the code, there is no errors.

Can someone help please ....

Thanks
0
Comment
Question by:venterm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 43

Accepted Solution

by:
TimCottee earned 1000 total points
ID: 17010109
Hi venterm,

You need to specify the DataTextField and DataValueField properties so that the dropdown knows what data to display:

            myConnection = New SqlConnection ("server=slserver;uid=;pwd=;database=meta_dev")
            SQL$ = ""
            SQL$ = SQL$ & " select      glpd_key     "
            SQL$ = SQL$ & " from        gl_period   "
            myConnection.Open()
            myCommand = New SqlCommand(SQL$, myConnection)
            myDataReader = myCommand.ExecuteReader()
            Me.ddl_glperiod.DataSource = myDataReader
            ddl_glPeriod.DataTextField = "glpd_key"
            ddl_glPeriod.DataValueField = "glpd_key"
            Me.ddl_glperiod.DataBind()
            'close connection to item_map_gl
            myConnection.Close()

        ddl_glperiod.SelectedIndex = 15

Tim Cottee
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Six Sigma Control Plans
Introduction to Processes

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question