Hi Friends,
in my application i m using cascading dropdown with stored values from databases.
my application shows on page1.aspx:
state: drop1
district: drop2
show marker: button
here the code for cascading dropdown is....
protected void BindContrydropdown()
{
conn.Open();
SqlCommand cmd = new SqlCommand("select * from ind_state", conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();
ddlstate.DataSource = ds;
ddlstate.DataTextField = "ind_state_name";
ddlstate.DataValueField = "ind_stat_id";
ddlstate.DataBind();
ddlstate.Items.Insert(0, new ListItem("--Select--", "0"));
ddldist.Items.Insert(0, new ListItem("--Select--", "0"));
}
protected void ddlstate_SelectedIndexChanged(object sender, EventArgs e)
{
conn.Open();
SqlCommand cmd = new SqlCommand(" Select * From ind_state_dist where ind_stat_id =" + ddlstate.SelectedValue, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();
ddldist.DataSource = ds;
ddldist.DataTextField = "ind_dist_name";
ddldist.DataValueField = "ind_dist_id";
ddldist.DataBind();
ddldist.Items.Insert(0, new ListItem("--Select--", "0"));
if (ddlstate.SelectedValue == "0")
{
ddldist.Items.Clear();
ddldist.Items.Insert(0, new ListItem("--Select--", "0"));
}
}
when i choose the state depends on district ll display here .....
for example i choose "TAMILNADU" and district "CHENNAI"
then press show Marker button
Session["DlistIndex"] = ddlstate.SelectedValue;
Session["DlistInd"] = ddldist.SelectedValue;
Response.Redirect(ddlstate.SelectedValue + ".aspx");
in my page2.aspx:
pageload:
if (!IsPostBack)
{
if (Session["DlistIndex"].ToString() != null )
{
stateid = Convert.ToInt32(Session["DlistIndex"]);
ddlstate.SelectedValue = stateid.ToString();
}
if (Session["DlistInd"].ToString() != null)
{
di = Convert.ToInt32(Session["DlistInd"]);
ddldist.SelectedValue = di.ToString();
}
BindRepeaterData();
BindContrydropdown();
}
here both stateid & di ll get the selected value of page1.aspx
i copied same code for drop down above in page2.aspx also......
here the problem is state dropdown ll dispaly the selected value from page1.aspx
but the district ll display "--select--" only..
why it was not fetching distric from database not shown selected dropdown?