Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi

I am having two pages in my website.
One in default.aspx and other is default2.aspx.

In my default.aspx page, I am having one country drop down list(list items are India, USA, UK).

In my default2.aspx page, I am having states drop down list(list items are Andhrapardesh, Assam, Texas, California, London).

Now if i select 'India' in my country drop down of default page, it should be redirect to default2 page and AndhraPardesh, Assam should be display in states drop down list.

How is it possible??
Posted
v2
Comments
__TR__ 10-Sep-12 2:14am    
Just out of curiosity, would you mind telling why do you want to have the 2 dropdown lists in separate pages? Why not have both the dropdowns in same page ?
sanwar_mal_jat 10-Sep-12 2:22am    
send your country_id selected indexchange event of your country drop down list from default.aspx page to default2.aspx and fill your state drop down list according country_id.........

You can do like this.
C#
protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
{
    Response.Redirect("default2.aspx?CountryID=" + ddlCountry.SelectedValue);
}

And in default2.aspx page...
C#
protected void Page_Load(object sender, EventArgs e)
{
     string country = String.Empty;
 
     if (!Page.IsPostBack)
     {
          if(Request.QueryString["CountryID"] != null)
          {
               country = Request.QueryString["CountryID"].ToString();
               PopulateStates(countryID);
          }
     }
}

Private void PopulateStates(string countryID)
{
     // Get the states from Database for the countryID and bind related values to 
     // the states dropdown.
}
 
Share this answer
 
v4
Comments
.netHelperClass 10-Sep-12 3:40am    
Non-invocable member 'string.Empty' cannot be used like a method.

this is the error i am getting
Sorry my mistake, it should be string country = String.Empty;
Use Query String for this:
Default.aspx.cs Page
C#
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
   {
       DropDownList str = sender as DropDownList;
       Response.Redirect("Default2.aspx?country=" + str.SelectedValue + "", false);
   }


Default2.aspx.cs Page
C#
if (Request.QueryString["country"] != null)
        {
            if (Request.QueryString["country"].ToString().ToUpper() == "INDIA")
            {
                DropDownList1.Items.Add("Andhrapardesh");
                DropDownList1.Items.Add("Assam");
            }
            else if (Request.QueryString["country"].ToString().ToUpper() == "USA")
            {
                DropDownList1.Items.Add("Texas");
                DropDownList1.Items.Add("California");
            }
            else if (Request.QueryString["country"].ToString().ToUpper() == "UK")
            {
                DropDownList1.Items.Add("London");
            }
        }
 
Share this answer
 
Hi,

You can use a session variable to store the selection of country.
When redirecting to your default2 page,in the page load bind the dropdown list based on that session variable.

Hope this helps.
 
Share this answer
 
Hello

Passing data by URL will make security issue. So its recommended you will store country id in session and redirect to default2.aspx page using server.transfer instead of response.redirect for application performance point of view.


Please let us know if needed any more assistance.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900