Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 3 levels of selection.
In the first level have to disply all the Country in a check box list from the database.
The user is allowed to select any number of Countries and based on those selections
I have to show the States which comes under each Countries in seperate checkbox lists.
The user is allowed to select any number of States and based on these selections
I have to show the disttric of each selected States.
please help to solve it.

i am using followind code but it is not working proper

C#
MySqlConnection con;
con = new MySqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString());

con.Open();
try
{

   for (int i = 0; i < CblistCountry.Items.Count; i++)
   {
      if (CblistCountry.Items[i].Selected)
      {
         string var = string.Empty;
         var += CblistCountry.Items[i].Value.ToString();


         string str = "SELECT * FROM add_state where COUNTRYID='" + var + "'";
         MySqlCommand cmd;
         cmd = new MySqlCommand(str, con);
         MySqlDataAdapter da = new MySqlDataAdapter(cmd);
         DataSet ds = new DataSet();
         da.Fill(ds);


      if (ds.Tables[0].Rows.Count > 0)
      {
         CblistState.DataSource = ds;
         CblistState.DataTextField = "StateName";
         CblistState.DataValueField = "StateID";
         CblistState.DataBind();
      }
    }
  }
}
catch
{

}

}
Posted
Updated 8-Apr-15 20:32pm
v5
Comments
Suvendu Shekhar Giri 9-Apr-15 2:18am    
what exactly "not working" means? Is it giving any error?
osmo33 9-Apr-15 2:27am    
no, it fatch state only for first selected Country;
but i want to show all states on chechbox list based on CID of selected country
and same selection of states distric.
Maciej Los 9-Apr-15 14:17pm    
Your code sql injection vulnerable...

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