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
ID: 24061480
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

ID: 24061849
It works!!
Thanks Oobayly!!

Author Closing Comment

ID: 31566313
Right on the money the first time!! Thanks!!

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 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