?
Solved

ASP.net VB load unique items to dropdown list

Posted on 2011-02-20
3
Medium Priority
?
711 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:Murray Brown
[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
  • 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 2000 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:Murray Brown
ID: 34949172
thanks very much
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
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 …
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

650 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