Hi
i am having two pages in my website
one in default. asp x 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 the 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??
Satyapriya NayakPosted Sep 10, 2012, 1:04 PM
Create table area(state varchar(50), country varchar(50))
Delhi
India
Orissa
India
Bihar
India
West Bengal
India
Maharastra
India
Newyork
Usa
California
Usa
Ottawa
Canada
Sydney
Australia
Perth
Australia
Berlin
Germany
sivaram reddyPosted Sep 10, 2012, 9:24 AM
Satyapriya NayakPosted Sep 10, 2012, 7:19 AM
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Country_state._Default" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Country_state
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
if (!IsPostBack)
{
DropDownList_country.Items.Add("Choose country");
con.Open();
str = "select country from area group by country";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
DropDownList_country.Items.Add(reader["country"].ToString());
}
reader.Close();
con.Close();
}
}
protected void DropDownList_country_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Redirect("default2.aspx?CountryID=" + DropDownList_country.SelectedValue);
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default2.aspx.cs" Inherits="Country_state.Default2" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Country_state
{
public partial class Default2 : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str,s1;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
DropDownList_state.Items.Clear();
SqlConnection con = new SqlConnection(strConnString);
con.Open();
s1 = Request.QueryString["CountryID"];
str = "select * from area where country='" + s1 + "'";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
DropDownList_state.Items.Add(reader["state"].ToString());
}
reader.Close();
con.Close();
}
}
}
Thanks
If this post helps you mark it as answer
sivaram reddyPosted Sep 10, 2012, 3:56 AM
in my default.aspx.cs
i have written the code
Gopesh SharmaPosted Sep 10, 2012, 3:30 AM
You can do that by passing values to another page using query string. In the next .aspx page when you will get India, just filter the result according to the value entered in the first page.