[WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.Web.Script.Services.ScriptService] public class ServiceCS : System.Web.Services.WebService { [WebMethod] public CascadingDropDownNameValue[] GetCountries(string knownCategoryValues) { string query = "SELECT DISTINCT Country FROM Customers"; List<cascadingdropdownnamevalue> countries = GetData(query); return countries.ToArray(); } [WebMethod] public CascadingDropDownNameValue[] GetCities(string knownCategoryValues) { string country = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)["Country"]; string query = string.Format("SELECT DISTINCT City FROM Customers WHERE Country = '{0}'", country); List<cascadingdropdownnamevalue> cities = GetData(query); return cities.ToArray(); } [WebMethod] public CascadingDropDownNameValue[] GetVillages(string knownCategoryValues) { string village = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)["village"]; string query = string.Format("SELECT DISTINCT village FROM Customers WHERE City = '{1}'", village); List<cascadingdropdownnamevalue> vilgs = GetData(query); return vilgs.ToArray(); } private List<cascadingdropdownnamevalue> GetData(string query) { string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; SqlCommand cmd = new SqlCommand(query); List<cascadingdropdownnamevalue> values = new List<cascadingdropdownnamevalue>(); using (SqlConnection con = new SqlConnection(conString)) { con.Open(); cmd.Connection = con; using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { values.Add(new CascadingDropDownNameValue { name = reader[0].ToString(), value = reader[0].ToString() }); } reader.Close(); con.Close(); return values; } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)