Abhijit Chougule

Abhijit Chougule

  • NA
  • 12
  • 12.5k

asp.net cascading dropdown list data binding

Mar 10 2015 12:34 AM
I am trying to bind a drop downlist by selecting a country dropdownlist.On selected index changed of dropdoen list country,it should display the states belonging to that country.
 
 
I have written the code to bind the ddlstate as -------
 
protected void ddlcountry_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
int countryid = Convert .ToInt32(ddlcountry.SelectedValue);
//Select all States corresponding to the selected country
SqlDataAdapter adp = new SqlDataAdapter("select * from userstate where stid = " + countryid,con);
DataSet ds = new DataSet ();
adp.Fill(ds);
ddlstate.DataSource = ds;
ddlstate.DataTextField = "statename" ;
ddlstate.DataValueField = "statename" ;
ddlstate.DataBind();
ddlstate.Items.Insert(0, new ListItem ("--Select--" , "0" ));
}
catch ( Exception ex)
{
Response.Write( "Error occured : " + ex.Message.ToString());
}
finally
{
con.Close();
}
}
 
 
 
 It is giving error as
 
Input string was not in a correct format. 
 
 

Answers (1)