Click here to Skip to main content
15,911,531 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I am new to work on Classic ASP technology.

In my application I have a database table with 2 columns.

in the UI I have 2 drop downs.

Now I want to load the value to 2nd drop down depending on 1st dropdown value.

consider my table as below

column1 column2

1 -------- one

2 -------- two

3 -------- three

4 -------- four


Now If I select 1 in 1st dropdown one should be loaded to 2nd dropdown.

If I select 2 in 1st dropdown two should be loaded to 2nd dropdown.

How can I write code for this in Classic ASP? Pls help

thanks in advance.
Posted

C#
<body>
    <form id="form1" runat="server">
    <div>
        Select Country :<br />
        <asp:dropdownlist id="DropDownList1" runat="server" autopostback="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged" xmlns:asp="#unknown">
            <asp:listitem>-Select-</asp:listitem>
            <asp:listitem value="1">India</asp:listitem>
            <asp:listitem value="2">Australia</asp:listitem>
        </asp:dropdownlist>
        <br />
        Select State:<br />
        <asp:dropdownlist id="DropDownList2" runat="server" xmlns:asp="#unknown">
        </asp:dropdownlist>
    </div>
    </form>
</body>
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string[] statelistIndia = new string[] {"-Select-","Maharashtra","New Delhi" };
        string[] statelistAus = new string[] { "-Select-", "Victoria", "West Australia" };
        if (DropDownList1.SelectedValue=="1")
        {
            DropDownList2.DataSource = statelistIndia;
            DropDownList2.DataBind();
        }
        if (DropDownList1.SelectedValue == "2")
        {
            DropDownList2.DataSource = statelistAus;
            DropDownList2.DataBind();
        }

     
    }
 
Share this answer
 
You can do this by using javascript. here are the options and examples:

http://classicasp.aspfaq.com/forms/how-do-i-make-one-dropdown-depend-on-another.html[^]

populate the two dropdowns from the database and using javascript, filter the second dropdown.

Example of populating the database:
http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=126[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900