private void GetCities(int countryId) { try { DataRow[] rows = cityDT.Select("CountryId = " + countryId); DataTable temp = new DataTable(); temp.Columns.Add("Id", typeof(int)); temp.Columns.Add("Name", typeof(string)); temp.Columns.Add("CountryId", typeof(int)); for (int i = 0; i < rows.Length; i++) { DataRow newrow = temp.NewRow(); newrow["Id"] = rows[i]["Id"]; newrow["Name"] = rows[i]["Name"]; newrow["CountryId"] = rows[i]["CountryId"]; temp.Rows.Add(newrow); } CityDDL.DataSource = temp; CityDDL.DataTextField = "Name"; CityDDL.DataValueField = "Id"; CityDDL.DataBind(); } catch (Exception) { } }
//17 @students.ecu.edu protected void StateDDL_SelectedIndexChanged(object sender, EventArgs e) { CityDDL.Items.Clear(); DataView cityTbl = (DataView)userDataSource.Select(DataSourceSelectArguments.Empty); cityTbl.RowFilter = "State = '" + StateDDL.SelectedItem.Text + "'"; DataRowView row; string cityName; if (cityTbl.Count != 0) { for (int i = 0; i < cityTbl.Count; i++) { row = (DataRowView)cityTbl[i]; cityName = row["City"].ToString(); CityDDL.Items.Add(cityName); } CityDDL.DataBind(); } }