protected void PropertyState_SelectedIndexChanged1(object sender, EventArgs e) { try { Int64 StateId = Convert.ToInt64(PropertyState.SelectedValue.ToString() == "" ? "0" : PropertyState.SelectedValue.ToString()); SqlDataAdapter da = new SqlDataAdapter(); SqlCommand cmd = new SqlCommand("SP_City", cn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Mode", "SelectCityByStateId"); cmd.Parameters.AddWithValue("@StateId", StateId); da.SelectCommand = cmd; da.Fill(ds); if (ds.Tables.Count > 0) { if (ds.Tables[0].Rows.Count > 0) { PropertyCity.DataTextField = "CityName"; PropertyCity.DataValueField = "CityId"; PropertyCity.DataSource = ds; PropertyCity.DataBind(); PropertyCity.Items.Insert(0, new ListItem("---Select City---")); } else { PropertyCity.DataSource = null; PropertyCity.DataBind(); PropertyCity.Items.Insert(0, new ListItem("---Select City---")); } } else { PropertyCity.DataSource = null; PropertyCity.DataBind(); PropertyCity.Items.Insert(0, new ListItem("---Select City---")); } } catch (Exception e2) { Response.Write("Error occured : " + e2.Message.ToString()); } }
private void PropertyCityBind() { try { ds = objInteraction.CitySelectAll(); if (ds.Tables.Count > 0) { if (ds.Tables[0].Rows.Count > 0) { PropertyCity.DataTextField = "CityName"; PropertyCity.DataValueField = "CityId"; PropertyCity.DataSource = ds.Tables[0]; PropertyCity.DataBind(); PropertyCity.Items.Insert(0, new ListItem("---Select City---")); } else { PropertyCity.DataSource = null; PropertyCity.DataBind(); PropertyCity.Items.Insert(0, new ListItem("---Select City---")); } } else { PropertyCity.DataSource = null; PropertyCity.DataBind(); PropertyCity.Items.Insert(0, new ListItem("---Select City---")); } } catch (Exception ex) { } }