Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
1
Answer
asp.net cascading dropdown list data binding
Ask a question
Ask a question
Upload Source Code:
Select only zip and rar file.
Abhijit Chougule
9y
432
1
Reply
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.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
Display data with in grid
Vb.Net??