Click here to Skip to main content
14,084,843 members
Click here to Skip to main content
Add your own
alternative version

Stats

47.9K views
14 downloads
17 bookmarked
Posted 13 Feb 2008
Licenced Ms-PL

Cascading Dropdonlist in ASP.NET

, 13 Feb 2008
Rate this:
Please Sign up or sign in to vote.
Cascading dropdown list in asp.net using MYSQL database

Introduction

This is the code for Cascading dropdown list which helps to know how the dropdownlists are cascaded and how the code written and helps to know adding the items to the dropdown list from the database.

Using the code

Here in this below code it shows that when the first dropdown's selected text changes immediately second dropdown loads and it helps in the case a user has some super categories and after selecting that super categories it has to display the sub categories respective to the values selected in the dropdownlist 1.

In below code connection string for mysql is assigned to a variable and here i used ODBC to establish a connection to the database and table.Data in the dropdownlist1 is populated automatically and after selecting first second drop down gets populated with the help of "Do while " statement , the data goes on adding up to the condition is false.


    Protected Sub country_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles country.SelectedIndexChanged
        Dim myreader As Odbc.OdbcDataReader
        Dim ConnStr As String = "Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=TaxPRo;uid=root;pwd=password;option=3"
        Dim con As OdbcConnection = New OdbcConnection(ConnStr)
        Dim cmd As OdbcCommand = New OdbcCommand("select * from states where country_id=" & country.SelectedValue & " order by state_name", con)
        con.Open()
        
        myreader = cmd.ExecuteReader()
       
        
        Do While myreader.Read()
            
            state.Items.Add(New ListItem(myreader("state_name"), myreader("country_id")))
                      
        Loop
        myreader.Read()
        state.DataValueField = ("country_id")
    End Sub
 <%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Odbc" %>

Remember to import these above Namesapce if you are using ODBC

By

Avinash Desai

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

Share

About the Author

Avinash Desai
S.N.Software Technology Bangalore
India India
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 1 Pin
C.V.Vikram3-Sep-09 0:21
memberC.V.Vikram3-Sep-09 0:21 
GeneralMy vote of 1 Pin
Philip Smith28-Aug-09 3:41
memberPhilip Smith28-Aug-09 3:41 
Generalhumm... Pin
Riad MS Afyouni16-Feb-08 21:47
memberRiad MS Afyouni16-Feb-08 21:47 
GeneralRe: humm... Pin
Avinash Desai17-Feb-08 18:28
memberAvinash Desai17-Feb-08 18:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.190518.1 | Last Updated 14 Feb 2008
Article Copyright 2008 by Avinash Desai
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid