Solved

ASP.net VB load unique items to dropdown list

Posted on 2011-02-20
3
706 Views
Last Modified: 2012-05-11
Hi
In ASP.net 4 I have a dropdownlist control that I want to populate with the unique items of one of the columns in a sQL table that is in my project. What VB code would I use to do this?
0
Comment
Question by:murbro
  • 2
3 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 34940744
Get the data from database , and in query itself get the unique data
see the code below . repleace your query with Sql query

Dim strConnectionString As String = "connetion string here"
    Dim cnn As New SqlConnection(strConnectionString)
    Dim cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand("SELECT distinct col1 FROM tableName ", cnn)
    cmd.CommandType = CommandType.Text
    Dim dacmd As New SqlClient.SqlDataAdapter(cmd)
    Dim dscmd As New DataSet
    dacmd.Fill(dscmd)
    DropDownList11.DataSource = dscmd.Tables(0)
    DropDownList11.DataBind()
0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 34940746
Get the data from database , and in query itself get the unique data
see the code below . repleace your query with Sql query

Dim strConnectionString As String = "connetion string here"
    Dim cnn As New SqlConnection(strConnectionString)
    Dim cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand("SELECT distinct col1 FROM tableName ", cnn)
    cmd.CommandType = CommandType.Text
    Dim dacmd As New SqlClient.SqlDataAdapter(cmd)
    Dim dscmd As New DataSet
    dacmd.Fill(dscmd)
    DropDownList11.DataSource = dscmd.Tables(0)
DropDownList11.DataTextField = "col1"
DropDownList11.DataValueField = "col1"
    DropDownList11.DataBind()
0
 

Author Closing Comment

by:murbro
ID: 34949172
thanks very much
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

861 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