Solved

ASP.net VB load unique items to dropdown list

Posted on 2011-02-20
3
708 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
[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 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
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…

737 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