Solved

ASP.net VB load unique items to dropdown list

Posted on 2011-02-20
3
697 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 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