Dear Sir/Madam,
I want to select country, based on the country the corresponding states wants to retrieve... But i have got everything whatever stored in the database table...
This is my design page
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<div>
<asp:UpdatePanel ID="CountryPanel" runat="server">
<contenttemplate>
<tr>
<td>
<asp:Label ID="lbl_Country" runat="server" Text="Country" Width="150px">
</td>
<td>
<asp:DropDownList ID="DDL_Country" runat="server" Width="150px"
AutoPostBack="true" AppendDataBoundItems="true"
onselectedindexchanged="DDL_Country_SelectedIndexChanged">
</td>
</tr>
</contenttemplate>
<triggers>
<asp:AsyncPostBackTrigger ControlID="DDL_Country" />
</triggers>
<br />
<asp:UpdatePanel ID="StatePanel" runat="server">
<contenttemplate>
<tr>
<td>
<asp:Label ID="lbl_State" runat="server" Text="State" Width="150px">
</td>
<asp:DropDownList ID="DDL_State" runat="server" Width="150px"
AutoPostBack="true" AppendDataBoundItems="true" onselectedindexchanged="DDL_State_SelectedIndexChanged">
<td>
</td>
</tr>
</contenttemplate>
<triggers>
<asp:AsyncPostBackTrigger ControlID="DDL_State" />
</triggers>
<br />
</div>
</form>
</body>
This is my code behind file
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Country();
}
}
public void Country()
{
con.Open();
cmd = new SqlCommand("select CountryId,Country from Country", con);
dr = cmd.ExecuteReader();
DDL_Country.DataSource = dr;
DDL_Country.Items.Clear();
DDL_Country.Items.Add("-Select Country-");
DDL_Country.DataTextField = "Country";
DDL_Country.DataValueField = "CountryId";
DDL_Country.DataBind();
con.Close();
}
public void State()
{
con.Open();
cmd = new SqlCommand("select state_ID,State_Name from stat", con);
dr = cmd.ExecuteReader();
DDL_State.DataSource = dr;
DDL_State.Items.Clear();
DDL_State.Items.Add("-Select State-");
DDL_State.DataTextField = "State_Name";
DDL_State.DataValueField = "state_ID";
DDL_State.DataBind();
con.Close();
}
protected void DDL_Country_SelectedIndexChanged(object sender, EventArgs e)
{
State();
}
Please help me...
Consider i have countries like India , Pakistan, Srilanka...
If i select India means India's states like Tamilnadu, Karnataka only want to retrieve from the database. But in my case all the states (India,Pakistan,Srilanka) retrieving from the db...
Thanks in Advance...