<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Populating a dropdown list with unique values' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Populating a dropdown list with unique values' posted on the 'VB.NET' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Sat, 25 May 2013 16:53:37 -0700</pubDate>
    <lastBuildDate>Sat, 25 May 2013 16:53:37 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Populating a dropdown list with unique values</title>
      <link>http://www.programmersheaven.com/mb/VBNET/263349/263349/populating-a-dropdown-list-with-unique-values/</link>
      <description>Hello, I am trying to find some help on displaying UNIQUE values in a dropdown list populated from a SQL server database.&lt;br /&gt;
&lt;br /&gt;
I am using .NET framework with VB as the language and SQL server for data. I have the following code for populating the dropdown field CategoryList:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;asp:dropdownlist id="CategoryList" runat="server" Height="26px" Width="139px"&amp;gt;&amp;lt;/asp:dropdownlist&amp;gt;&lt;br /&gt;
&lt;br /&gt;
------------------------------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
Dim strconnection As SqlConnection&lt;br /&gt;
Dim myda As SqlDataAdapter&lt;br /&gt;
Dim ds As DataSet&lt;br /&gt;
&lt;br /&gt;
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load&lt;br /&gt;
        'Put user code to initialize the page here&lt;br /&gt;
        strconnection = New SqlConnection("Server=localhost;uid=sa;password=;d
atabase=somename;")&lt;br /&gt;
        myda = New SqlDataAdapter("Select * from tblDocs ", strconnection)&lt;br /&gt;
        ds = New DataSet&lt;br /&gt;
        myda.Fill(ds, "AllTables")&lt;br /&gt;
&lt;br /&gt;
        CategoryList.DataSource = ds&lt;br /&gt;
        CategoryList.DataSource = ds.Tables(0)&lt;br /&gt;
        CategoryList.DataTextField = ds.Tables(0).Columns("Category").ColumnName.ToStri
ng()&lt;br /&gt;
        CategoryList.DataValueField = ds.Tables(0).Columns("Category").ColumnName.ToStri
ng()&lt;br /&gt;
        CategoryList.DataBind()&lt;br /&gt;
&lt;br /&gt;
End Sub&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
I can get the values into the dropdown list correctly but they appear repetitively in the list as they do in the SQL databases, for eg:&lt;br /&gt;
&lt;br /&gt;
Category:&lt;br /&gt;
&lt;br /&gt;
Van&lt;br /&gt;
Van&lt;br /&gt;
Van&lt;br /&gt;
SUV&lt;br /&gt;
Sedan&lt;br /&gt;
&lt;br /&gt;
What can I do to make the drop down list unique so that values do not appear several times?&lt;br /&gt;
&lt;br /&gt;
Thanks for any suggestions or help.&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/VBNET/263349/263349/populating-a-dropdown-list-with-unique-values/</guid>
      <pubDate>Wed, 16 Jun 2004 10:44:45 -0700</pubDate>
      <category>VB.NET</category>
    </item>
    <item>
      <title>Re: Populating a dropdown list with unique values</title>
      <link>http://www.programmersheaven.com/mb/VBNET/263349/263359/re-populating-a-dropdown-list-with-unique-values/#263359</link>
      <description>: Hello, I am trying to find some help on displaying UNIQUE values in a dropdown list populated from a SQL server database.&lt;br /&gt;
: &lt;br /&gt;
: I am using .NET framework with VB as the language and SQL server for data. I have the following code for populating the dropdown field CategoryList:&lt;br /&gt;
: &lt;br /&gt;
: &amp;lt;asp:dropdownlist id="CategoryList" runat="server" Height="26px" Width="139px"&amp;gt;&amp;lt;/asp:dropdownlist&amp;gt;&lt;br /&gt;
: &lt;br /&gt;
: ------------------------------------------------------------------------------------------------------&lt;br /&gt;
: &lt;br /&gt;
: Dim strconnection As SqlConnection&lt;br /&gt;
: Dim myda As SqlDataAdapter&lt;br /&gt;
: Dim ds As DataSet&lt;br /&gt;
: &lt;br /&gt;
: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load&lt;br /&gt;
:         'Put user code to initialize the page here&lt;br /&gt;
:         strconnection = New SqlConnection("Server=localhost;uid=sa;password=;d
atabase=somename;")&lt;br /&gt;
:         myda = New SqlDataAdapter("Select * from tblDocs ", strconnection)&lt;br /&gt;
:         ds = New DataSet&lt;br /&gt;
:         myda.Fill(ds, "AllTables")&lt;br /&gt;
: &lt;br /&gt;
:         CategoryList.DataSource = ds&lt;br /&gt;
:         CategoryList.DataSource = ds.Tables(0)&lt;br /&gt;
:         CategoryList.DataTextField = ds.Tables(0).Columns("Category").ColumnName.ToStri
ng()&lt;br /&gt;
:         CategoryList.DataValueField = ds.Tables(0).Columns("Category").ColumnName.ToStri
ng()&lt;br /&gt;
:         CategoryList.DataBind()&lt;br /&gt;
: &lt;br /&gt;
: End Sub&lt;br /&gt;
: &lt;br /&gt;
: -------------------------------------------------------------------------&lt;br /&gt;
: &lt;br /&gt;
: I can get the values into the dropdown list correctly but they appear repetitively in the list as they do in the SQL databases, for eg:&lt;br /&gt;
: &lt;br /&gt;
: Category:&lt;br /&gt;
: &lt;br /&gt;
: Van&lt;br /&gt;
: Van&lt;br /&gt;
: Van&lt;br /&gt;
: SUV&lt;br /&gt;
: Sedan&lt;br /&gt;
: &lt;br /&gt;
: What can I do to make the drop down list unique so that values do not appear several times?&lt;br /&gt;
: &lt;br /&gt;
: Thanks for any suggestions or help.&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
Perhaps??? It is hard to tell what you database looks like.&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
select distinct category from tblDocs
&lt;/pre&gt;&lt;br /&gt;
\\--||--//&lt;br /&gt;
&amp;lt;NATLOZ&amp;gt;&lt;br /&gt;
//--||--\\&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/VBNET/263349/263359/re-populating-a-dropdown-list-with-unique-values/#263359</guid>
      <pubDate>Wed, 16 Jun 2004 12:08:48 -0700</pubDate>
      <category>VB.NET</category>
    </item>
    <item>
      <title>Re: Populating a dropdown list with unique values</title>
      <link>http://www.programmersheaven.com/mb/VBNET/263349/263364/re-populating-a-dropdown-list-with-unique-values/#263364</link>
      <description>: : Hello, I am trying to find some help on displaying UNIQUE values in a dropdown list populated from a SQL server database.&lt;br /&gt;
: : &lt;br /&gt;
: : I am using .NET framework with VB as the language and SQL server for data. I have the following code for populating the dropdown field CategoryList:&lt;br /&gt;
: : &lt;br /&gt;
: : &amp;lt;asp:dropdownlist id="CategoryList" runat="server" Height="26px" Width="139px"&amp;gt;&amp;lt;/asp:dropdownlist&amp;gt;&lt;br /&gt;
: : &lt;br /&gt;
: : -----------------------------------------&lt;br /&gt;
: : &lt;br /&gt;
: : Dim strconnection As SqlConnection&lt;br /&gt;
: : Dim myda As SqlDataAdapter&lt;br /&gt;
: : Dim ds As DataSet&lt;br /&gt;
: : &lt;br /&gt;
: : Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load&lt;br /&gt;
: :         'Put user code to initialize the page here&lt;br /&gt;
: :         strconnection = New SqlConnection("Server=localhost;uid=sa;password=;d
atabase=somename;")&lt;br /&gt;
: :         myda = New SqlDataAdapter("Select * from tblDocs ", strconnection)&lt;br /&gt;
: :         ds = New DataSet&lt;br /&gt;
: :         myda.Fill(ds, "AllTables")&lt;br /&gt;
: : &lt;br /&gt;
: :         CategoryList.DataSource = ds&lt;br /&gt;
: :         CategoryList.DataSource = ds.Tables(0)&lt;br /&gt;
: :         CategoryList.DataTextField = ds.Tables(0).Columns("Category").ColumnName.ToStri
ng()&lt;br /&gt;
: :         CategoryList.DataValueField = ds.Tables(0).Columns("Category").ColumnName.ToStri
ng()&lt;br /&gt;
: :         CategoryList.DataBind()&lt;br /&gt;
: : &lt;br /&gt;
: : End Sub&lt;br /&gt;
: : &lt;br /&gt;
: : -------------------------------------------------------------------------&lt;br /&gt;
: : &lt;br /&gt;
: : I can get the values into the dropdown list correctly but they appear repetitively in the list as they do in the SQL databases, for eg:&lt;br /&gt;
: : &lt;br /&gt;
: : Category:&lt;br /&gt;
: : &lt;br /&gt;
: : Van&lt;br /&gt;
: : Van&lt;br /&gt;
: : Van&lt;br /&gt;
: : SUV&lt;br /&gt;
: : Sedan&lt;br /&gt;
: : &lt;br /&gt;
: : What can I do to make the drop down list unique so that values do not appear several times?&lt;br /&gt;
: : &lt;br /&gt;
: : Thanks for any suggestions or help.&lt;br /&gt;
: : &lt;br /&gt;
------------------------------------------------------------&lt;br /&gt;
: &lt;br /&gt;
: Perhaps??? It is hard to tell what you database looks like.&lt;br /&gt;
: &lt;pre class="sourcecode"&gt;
: select distinct category from tblDocs
: &lt;/pre&gt;&lt;br /&gt;
: \\--||--//&lt;br /&gt;
: &amp;lt;NATLOZ&amp;gt;&lt;br /&gt;
: //--||--\\&lt;br /&gt;
: &lt;br /&gt;
------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
Thanks, "distinct" did the trick!&lt;br /&gt;
&lt;br /&gt;
Do you know how I can make the dropdown list field editable on the .aspx form so that when the users create a new record, they have a choice of selecting a category, but if one does not exist, they should be able to type a new category in the field itself and submit the form?&lt;br /&gt;
&lt;br /&gt;
Is this possible?&lt;br /&gt;
&lt;br /&gt;
Thanks again!&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/VBNET/263349/263364/re-populating-a-dropdown-list-with-unique-values/#263364</guid>
      <pubDate>Wed, 16 Jun 2004 12:25:17 -0700</pubDate>
      <category>VB.NET</category>
    </item>
    <item>
      <title>Re: Populating a dropdown list with unique values</title>
      <link>http://www.programmersheaven.com/mb/VBNET/263349/263368/re-populating-a-dropdown-list-with-unique-values/#263368</link>
      <description>I would think that all you would have to do is save to your database whatever cboWhatever.text is (this will be whether or not they select it from the drop-down or manually type it in to the dropdown), and when you refresh the combo box it will have the newly saved record in your distinct select. This should work since you are not basing anything on a primary key in the database for the Category.&lt;br /&gt;
&lt;br /&gt;
\\--||--//&lt;br /&gt;
&amp;lt;NATLOZ&amp;gt;&lt;br /&gt;
//--||--\\&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/VBNET/263349/263368/re-populating-a-dropdown-list-with-unique-values/#263368</guid>
      <pubDate>Wed, 16 Jun 2004 12:51:20 -0700</pubDate>
      <category>VB.NET</category>
    </item>
  </channel>
</rss>