protected void Page_Load(object sender, EventArgs e) { if (!this.Page.IsPostBack) { var context = new CountriesDataContext(); this.DropDownListCountries.DataSource = context.Countries; this.DropDownListCountries.DataBind(); this.RebindTowns(); } }
private void RebindTowns() { var countryId = int.Parse(this.DropDownListCountries.SelectedValue); var context = new CountriesDataContext(); var towns = from town in context.Towns where town.CountryID == countryId select town; this.DropDownListTowns.DataSource = towns; this.DropDownListTowns.DataBind(); }