protected void PropertyCountry_SelectedIndexChanged(object sender, EventArgs e) { try { Int64 CountryId = Convert.ToInt64(PropertyCountry.SelectedValue.ToString() == "" ? "0" : PropertyCountry.SelectedValue.ToString()); SqlDataAdapter da = new SqlDataAdapter(); SqlCommand cmd = new SqlCommand("SP_State", cn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Mode", "SelectStateByCountryId"); cmd.Parameters.AddWithValue("@CountryId", CountryId); da.SelectCommand = cmd; da.Fill(ds); if (ds.Tables.Count > 0) { if (ds.Tables[0].Rows.Count > 0) { PropertyState.DataTextField = "StateName"; PropertyState.DataValueField = "StateId"; PropertyState.DataSource = ds; PropertyState.DataBind(); PropertyState.Items.Insert(0, new ListItem("---Select State---")); } else { PropertyState.DataSource = null; PropertyState.DataBind(); PropertyState.Items.Insert(0, new ListItem("---Select State---")); } } else { PropertyState.DataSource = null; PropertyState.DataBind(); PropertyState.Items.Insert(0, new ListItem("---Select State---")); } } catch (Exception e2) { Response.Write("Error occured : " + e2.Message.ToString()); } }
private void PropertyStateBind() { try { ds = objInteraction.StateSelectAll(); if (ds.Tables.Count > 0) { if (ds.Tables[0].Rows.Count > 0) { PropertyState.DataTextField = "StateName"; PropertyState.DataValueField = "StateId"; PropertyState.DataSource = ds.Tables[0]; PropertyState.DataBind(); PropertyState.Items.Insert(0, new ListItem("---Select State---")); } else { PropertyState.DataSource = null; PropertyState.DataBind(); PropertyState.Items.Insert(0, new ListItem("---Select State---")); } } else { PropertyState.DataSource = null; PropertyState.DataBind(); PropertyState.Items.Insert(0, new ListItem("---Select State---")); } } catch (Exception ex) { } }