[Csharp]
<% @ Control Language = "C #" AutoEventWireup = "true" CodeFile = "PCAControl. ascx. cs" Inherits = "PCAControl" %>
<Asp: ScriptManager ID = "ScriptManager1" runat = "server">
</Asp: ScriptManager>
<Asp: UpdatePanel ID = "UpdatePanel1" runat = "server">
<ContentTemplate>
<Asp: DropDownList ID = "ddlProvice" runat = "server" AppendDataBoundItems = "true" AutoPostBack = "true"
OnSelectedIndexChanged = "ddlProvice_SelectedIndexChanged">
<Asp: ListItem Text = "-select a province-" Value = ""> </asp: ListItem>
</Asp: DropDownList>
<Asp: DropDownList ID = "ddlCity" runat = "server" AutoPostBack = "true"
Onselectedindexchanged = "ddlCity_SelectedIndexChanged">
<Asp: ListItem Text = "-select city-" Value = ""> </asp: ListItem>
</Asp: DropDownList>
<Asp: DropDownList ID = "ddlArea" runat = "server">
<Asp: ListItem Text = "-select the county-" Value = ""> </asp: ListItem>
</Asp: DropDownList>
</ContentTemplate>
</Asp: UpdatePanel>
[Csharp]
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Using System. Data;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Public partial class PCAControl: System. Web. UI. UserControl
{
Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack)
{
BindProvince ();
}
}
// Load the province
Protected void BindProvince ()
{
DataTable dt = Maticsoft. DBUtility. DbHelperOra. Query ("select distinct province from SY_CITYCODE group by province"). Tables [0];
DdlProvice. DataTextField = "PROVINCE ";
DdlProvice. DataValueField = "PROVINCE ";
DdlProvice. DataSource = dt;
DdlProvice. DataBind ();
}
// Load the city
Protected void ddlProvice_SelectedIndexChanged (object sender, EventArgs e)
{
String SelectPro = ddlProvice. SelectedValue;
If (! String. IsNullOrEmpty (SelectPro ))
{
DdlCity. Items. Clear ();
DdlCity. AppendDataBoundItems = true;
DdlCity. Items. Insert (0, new ListItem ("-select city -",""));
DataTable dt1 = Maticsoft. DBUtility. DbHelperOra. Query ("select city from SY_CITYCODE Where PROVINCE = '" + SelectPro + "'group By City"). Tables [0];
DdlCity. DataTextField = "CITY ";
DdlCity. DataValueField = "CITY ";
DdlCity. DataSource = dt1;
DdlCity. DataBind ();
}
}
// Load county/district
Protected void ddlCity_SelectedIndexChanged (object sender, EventArgs e)
{
String SelectCity = ddlCity. SelectedValue;
If (! String. IsNullOrEmpty (SelectCity ))
{
DdlArea. Items. Clear ();
DdlArea. AppendDataBoundItems = true;
DdlArea. Items. Insert (0, new ListItem ("-select the county -",""));
DataTable dt2 = Maticsoft. DBUtility. DbHelperOra. Query ("select area from SY_CITYCODE Where CITY = '" + SelectCity + "'"). Tables [0];
DdlArea. DataTextField = "AREA ";
DdlArea. DataValueField = "AREA ";
DdlArea. DataSource = dt2;
DdlArea. DataBind ();
}
}
}
Call page
Protected void button#click (object sender, EventArgs e)
{
String SelectedProv = (DropDownList) PCAControl1.FindControl ("ddlProvice"). SelectedValue;
String SelectedCity = (DropDownList) PCAControl1.FindControl ("ddlCity"). SelectedValue;
String SelectedArea = (DropDownList) PCAControl1.FindControl ("ddlArea"). SelectedValue;
MSCL. JsHelper. Alert (SelectedProv + "-" + SelectedCity + "-" + SelectedArea, Page );
}