pls give me the complete code for it ..i tryed but not getting the output..pls help..iam pasting the code here but no output
SqlConnection cn = new SqlConnection(ConfigurationSettings.AppSettings["con"].ToString());
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("sql is connected");
SqlDataAdapter da = new SqlDataAdapter("select countryid,countryname from countryname", cn);
DataSet ds = new DataSet();
da.Fill(ds,"countryname");
ddlcountryname.DataSource = ds.Tables["countryname"];
ddlcountryname.DataTextField = "countryname";
ddlcountryname.DataValueField = "countryid";
ddlcountryname.DataBind();
}
protected void ddlcountryname_SelectedIndexChanged(object sender, EventArgs e)
{
string country_id;
country_id = ddlcountryname.SelectedValue.ToString();
SqlDataAdapter da1=new SqlDataAdapter("select stateid,statename from statename where countryid=' country_id'",cn);
DataSet ds1 = new DataSet();
da1.Fill(ds1, "statename");
ddlstatename.DataSource = ds1.Tables["statename"];
ddlstatename.DataTextField = "statename";
ddlstatename.DataValueField = "stateid";
ddlstatename.DataBind();
}
my database is something like this...i have two tables countryname(countryid identity(1,1),countryname) and statename(stateid identity(100,1),statename,countryid)
so i have inserted 78 countries in country table in tat 73rd is india...
n i have inserted states of india in statename table(28)..how to get india's states wen india in selected