Drop Down List Displays

Posted on 2009-04-03
Last Modified: 2013-11-26
I'm trying to populate a drop down list with one column of a sql view but instead I'm getting on every row. I've read about the column names etc. being incorrect etc and have checked that. I've also tried using dbo.vDepts and vDepts for the view name but it made no difference.

Thanks in advance!!
Imports System

Imports System.Collections

Imports System.Data

Imports System.Net.Mail

Imports System.Net

Imports System.IO

Imports System.Security.Permissions

Imports System.Text

Imports System.DirectoryServices

Partial Public Class _Default

    Inherits System.Web.UI.Page

    Dim strUser As String

    Dim strDate As Date

    Dim DS As System.Data.DataSet

 Private Sub FillDropdown()

        Dim sConn As Data.SqlClient.SqlConnection

        Dim sComm As Data.SqlClient.SqlCommand

        Dim sAdapt As Data.SqlClient.SqlDataAdapter

        sConn = New Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("MyConnection2").ConnectionString)

        sComm = New Data.SqlClient.SqlCommand("Select Depts from dbo.vDepts", sConn)

        sAdapt = New Data.SqlClient.SqlDataAdapter(sComm)


        DS = New DataSet



        DropDownList10.DataSource = DS



    End Sub

Open in new window

Question by:JB4375
  • 2
LVL 15

Accepted Solution

oobayly earned 500 total points
Comment Utility
You should set the DataTextField property for the drop down list to the column you wish to display:
DropDownList10.DataTextField = "Depts "

Open in new window


Author Comment

Comment Utility
It works!!
Thanks Oobayly!!

Author Closing Comment

Comment Utility
Right on the money the first time!! Thanks!!

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now