Populating Data from two different tables in a Single DropdownList

Contributed by
Rating: 4 stars4 stars4 stars4 stars4 stars / 7
July 07, 2002
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement

A sample code to populate the data from two different tables in a dropdown

  • Create two database tables : tb_India , tb_USA
  • Fields in tb_India : tb_India_id,  tb_India_City , tb_India_State
  • Fields in tb_USA : tb_USA_id,  tb_USA_City , tb_USA_State
  • The demonstration shows how to bind the dropdownlist with the cities in both the tables

Step 1: main.aspx

<asp:DropDownList id= "DropDownList1" style= "Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px" runat="server"></asp:DropDownList>

 

Step 2: main.aspx.vb

Dim myconnection As New SqlClient.SqlConnection("Server=localhost;uid=sa;password=;database=northwind;")

Dim myda As New SqlClient.SqlDataAdapter("Select * from tb_USA", myconnection)

Dim ds As New DataSet()

myda.Fill(ds, "tb_USA")

myda.SelectCommand.CommandText = "Select * from tb_India"

myda.Fill(ds, "tb_India")

Dim i, j As Integer

Dim dc As DataColumn

Dim mystrval As String

Dim dt As DataTable

Dim dr As DataRow

For Each dt In ds.Tables

              For i = 0 To dt.Rows.Count - 1

                        For Each dc In dt.Columns

                                Select Case dc.ColumnName

                                     Case "tb_USA_City"

                                         mystrval = mystrval & dt.Rows(i)(dc.ColumnName).ToString

                                     Case "tb_India_City"

                                        mystrval = mystrval & dt.Rows(i)(dc.ColumnName).ToString

                                 End Select

                        Next

                      DropDownList1.Items.Add(mystrval)

                      mystrval = "" 

              Next

Next

 

blog comments powered by Disqus
ASP CODE ARTICLES

- ASP Forms
- ASP: The Beginning
- Getting Remote Files With ASP Continued
- Inbox and Outbox Manipulation in ASP
- Relational DropDownList Using VB.NET
- Ad Tracking URL Hits
- Use ViewState to display one record per page...
- Send Email using ASP.NET formatted in HTML
- ASP File Explorer
- ASP/XML Interview questions by Srivatsan Sri...
- Pressing RETURN won't submit the form
- This shows how you get the TEXT of a combo r...
- Group Data by Adrian Forbes
- Multiple checkbox select sample
- Multiple checkbox select with all values sam...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials