I have created three xml files. One for countries, states, and province.
fo states
<?xml version="1.0" encoding="utf-8" standalone="yes" ?><states><state stateid="AL" name="Alabama" /><state stateid="CO" name="Colorado" /> .....</states> and for country<?xml version="1.0" encoding="utf-8" standalone="yes" ?><countries><country countryid="AF" name="Afghanistan" /><country countryid="DZ" name="Algeria" /> ...<countries>
for provinces.
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<provinces>
<!--Canadian Provinces-->
<provincename="Alberta"provinceid="AB" />
<provincename="British Columbia"provinceid="BC" />
...
</provinces>
So far I have,
the user selects canada then I just want the provinces to come up otherwise if the user selects usa then the states will come up otherwise if another country is chosen what value should i use Other? So there should be three changes or validations for the
state dropdownlist.
1) Countries
2) Provinces or States
3) Other
This is what I have for:
protectedvoid ddlCountry_SelectedIndexChanged(object sender,EventArgs e){
if (ddlCountry.SelectedValue =="CA") // Canada, set to provinces.{
DataSet DSStateProvince =newDataSet();DSStateProvince.ReadXml(Server.MapPath(
"GeneralInformation/Provinces.xml"));//Provinces.xmlddlStateProvince.DataSource = DSStateProvince;
ddlStateProvince.DataTextField = "name";ddlStateProvince.DataValueField =
"provinceid";// provinceidddlStateProvince.DataBind();
// Get the DropDownList's SelectedIndex int iRow = ddlCountry.SelectedIndex;}
elseif (ddlCountry.SelectedValue =="US"){
DataSet DSStateProvince =newDataSet();DSStateProvince.ReadXml(Server.MapPath(
"GeneralInformation/States.xml"));//Provinces.xmlddlStateProvince.DataSource = DSStateProvince;
ddlStateProvince.DataTextField = "name";ddlStateProvince.DataValueField =
"stateid";// provinceidddlStateProvince.DataBind();
// Get the DropDownList's SelectedIndex int iRow = ddlCountry.SelectedIndex;}
else{
DataSet DSStateProvince =newDataSet();state.Items.Insert(0,newListItem("Select One",""));// I want to add None?
}
}
protectedvoid Page_Load(object sender,EventArgs e){
if (!this.IsPostBack){
// Create a random code and store it in the Session object.this.Session["CaptchaImageText"] = GenerateRandomCode();// Populate Gender ListDataSet DSGenders =newDataSet();DSGenders.ReadXml(Server.MapPath("GeneralInformation/Genders.xml"));
ddlGender.DataSource = DSGenders;
ddlGender.DataTextField =
"name"; ddlGender.DataValueField = "genderid";ddlGender.DataBind();
// Populate States ListDataSet DSStateProvince =newDataSet();
DSStateProvince.ReadXml(Server.MapPath(
"GeneralInformation/States.xml"));//Provinces.xmlddlStateProvince.DataSource = DSStateProvince;
ddlStateProvince.DataTextField = "name";ddlStateProvince.DataValueField =
"stateid";// provinceidddlStateProvince.DataBind();
////Populate Countries ListDataSet DSCountries =newDataSet();DSCountries.ReadXml(Server.MapPath("GeneralInformation/countries.xml"));
ddlCountry.DataSource = DSCountries;
ddlCountry.DataTextField =
"name"; ddlCountry.DataValueField = "countryid";ddlCountry.DataBind();
// Allow AutoPostBacks ddlCountry.AutoPostBack = true;// Set the DropDownList's initial value ddlCountry.SelectedValue = "US";// Get the DropDownList's SelectedIndex int iRow = ddlCountry.SelectedIndex;}
else{
// On a postback, check the user input.if (this.CodeNumberTextBox.Text ==this.Session["CaptchaImageText"].ToString()){
// Display an informational message.this.MessageLabel.CssClass ="info";this.MessageLabel.Text ="Correct!";}
else{
// Display an error message.this.MessageLabel.CssClass ="error";this.MessageLabel.Text ="ERROR: Incorrect, try again.";// Clear the input and create a new random code.this.CodeNumberTextBox.Text ="";this.Session["CaptchaImageText"] = GenerateRandomCode();}
}
}