c# - Getting errors with dependent dropdown lists -


i have 2 tables in sql server,

 country_id          country 1                   india 2                   australia 3                   netherlands 

the 2nd table states

 state_id           country_id      state 1                   2              abc 2                   2              xyz 3                   3              pqr 4                   1              lmn 5                   1              rst 

on page load country automatically come in dropdown1 , when select australia in first drop down, in 2nd drop down abc , xyz shown.

i did getting bad query error.

what correct query?

my code is:

protected void dropdownlist1_selectedindexchanged(object sender, eventargs e) {     adap = new sqldataadapter("select state table_state ,table_country country = '"             + dropdownlist1.selecteditem.tostring()              + "' on table_state.country_id = table_country.country_id", con);     con.open();     ds1 = new dataset();     adap.fill(ds1);     dropdownlist2.datasource = ds1;     dropdownlist2.datavaluefield = "state";     dropdownlist2.datatextfield = "state"     dropdownlist2.databind();     con.close(); } 

replace line in code dropdownlist1_selectedindexchanged method

 adap = new sqldataadapter("select state table_state country_id = '"                           + dropdownlist1.selectedvalue + "'", con); 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -