Probelm on cascading drop down selected values doesnt reflect on another page in c#?

Posted by Raghuldrag under C# on 4/30/2014 | Points: 10 | Views : 837 | Status : [Member] | Replies : 2
Hi Friends,

i ve two pages like def1.aspx and 25.aspx....

in def1.aspx i ve cascading drop down like ddl1=fruits choosed means,
dd2items ll show mango,apple,banana......

depends on the selected drope down values shown on 25.aspx.........

here ddl1=fruits selected value show on 25.aspx but dditems default null ..... wat was the problem ?




Responses

Posted by: Vuyiswamb on: 4/30/2014 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
can you show us your code?

Thank you for posting at Dotnetfunda
[Administrator]

Raghuldrag, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raghuldrag on: 4/30/2014 [Member] Starter | Points: 25

Up
0
Down
Hi Vuyiswamb,

in page1.aspx i made cascading dropdown

that code is


public DataSet GetData(string sqlQuery)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString);
SqlDataAdapter da = new SqlDataAdapter(sqlQuery, conn);
DataSet DS = new DataSet();
da.Fill(DS);
return DS;

}

public void PopulateContinentsDdl()
{

DataSet ds = GetData("select * from ind_state order by ind_stat_id");

ddlstate.DataSource = ds;
ddlstate.DataValueField = "ind_stat_id";
ddlstate.DataTextField = "ind_state_name";
ddlstate.DataBind();
ListItem listate = new ListItem("select State", "-1");
ddlstate.Items.Insert(0, listate);
ListItem lidist = new ListItem("select District", "0");
ddldist.Items.Insert(0, lidist);



}



protected void ddlstate_SelectedIndexChanged(object sender, EventArgs e)
{
ddldist.Enabled = true;
conn.Open();
//SqlDataAdapter da1 =

//ddldist.DataSource = GetData("select * from tbl_Countries where ContinentId='" + dd.SelectedValue.ToString() + "'");
ddldist.DataSource = GetData("select ind_dist_name,ind_dist_id from ind_state_dist where ind_stat_id ='" + ddlstate.SelectedValue.ToString() + "'");

ddldist.DataTextField = "ind_dist_name";
ddldist.DataValueField = "ind_dist_id";
ddldist.DataBind();
ListItem lidist = new ListItem("select District", "0");
ddldist.Items.Insert(0, lidist);


}
protected void SHOW_Click(object sender, EventArgs e)
{



Session["DlistIndex"] = ddlstate.SelectedIndex.ToString();
Session["DlistInd"] = ddldist.SelectedIndex.ToString();
Response.Redirect(ddlstate.SelectedValue + ".aspx");




}



in page2.aspx:
==============

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

if (Session["DlistIndex"].ToString() != null )
{

ddlstate.SelectedIndex = Convert.ToInt32((Session["DlistIndex"]).ToString());
}

if (Session["DlistInd"].ToString() != null)
{

ddldist.SelectedIndex = Convert.ToInt32((Session["DlistInd"]).ToString());

}




Raghuldrag, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response