public void BindCity() { int StateID; int.TryParse(DrpState.SelectedValue, out StateID); DataTable dtCity = HRMWcfService1.BALDropDownList.CityList(StateID); DrpCity.DataSource = dtCity; DrpCity.DataTextField = "CityName"; DrpCity.DataValueField = "CityID"; DrpCity.DataBind(); DrpCity.Items.Insert(0, new ListItem("---Select City---")); }
protected void DrpState_SelectedIndexChanged(object sender, EventArgs e) { if (DrpState.Text.Length > 0) { DataTable dt = MDC.getDataTable("select distinct City from RTO where State='" + DrpState.Text + "'"); if (dt.Rows.Count > 0) { DrpCity.DataSource = dt; DrpCity.DataTextField = "City"; DrpCity.DataValueField = "City"; DrpCity.DataBind(); } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { con.Open(); SqlCommand cmd = new SqlCommand("select * from city", con); SqlDataReader rdr = cmd.ExecuteReader(); DrpCity.DataSource = rdr; DrpCity.DataTextField = "Name"; DrpCity.DataValueField = "id"; DrpCity.DataBind(); rdr.Close(); } }