?
Solved

populate dropdownlist with datareader

Posted on 2006-06-29
1
Medium Priority
?
1,239 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

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.

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.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

777 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