using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using AjaxControlToolkit; using System.Collections.Specialized; using System.Configuration; using System.Data; using System.Data.SqlClient; /// /// Summary description for WebService1 /// [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. [System.Web.Script.Services.ScriptService()] public class WebService1 : System.Web.Services.WebService { SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); //Web method for bind country [WebMethod] public CascadingDropDownNameValue[] BindCountry(string knownCategoryValues, string category) { DataSet ds = new DataSet(); conn.Open(); SqlCommand cmd = new SqlCommand("select * from country", conn); SqlDataAdapter adp = new SqlDataAdapter(cmd); cmd.ExecuteNonQuery(); adp.Fill(ds); conn.Close(); List CountryDetails = new List(); foreach (DataRow DR in ds.Tables[0].Rows) { string id = DR["id"].ToString(); string Country = DR["Country"].ToString(); CountryDetails.Add(new CascadingDropDownNameValue(Country, id)); } return CountryDetails.ToArray(); } //Web method for bind state [WebMethod] public CascadingDropDownNameValue[] BindState(string knownCategoryValues, string category) { DataSet ds = new DataSet(); int id; StringDictionary CountryDetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); id = Convert.ToInt32(CountryDetails["Country"]); conn.Open(); SqlCommand cmd = new SqlCommand("select * from State where id=@id", conn); cmd.Parameters.AddWithValue("@id", id); cmd.ExecuteNonQuery(); SqlDataAdapter adp = new SqlDataAdapter(cmd); adp.Fill(ds); conn.Close(); List StateDetails = new List(); foreach (DataRow DR in ds.Tables[0].Rows) { string Sid = DR["Sid"].ToString(); string StateName = DR["StateName"].ToString(); StateDetails.Add(new CascadingDropDownNameValue(StateName, Sid)); } return StateDetails.ToArray(); } //Web method for bind city [WebMethod] public CascadingDropDownNameValue[] BindCity(string knownCategoryValues, string category) { DataSet ds = new DataSet(); int Sid; StringDictionary statedetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); Sid = Convert.ToInt32(statedetails["State"]); conn.Open(); SqlCommand cmd = new SqlCommand("Select * from Region where Sid=@Sid", conn); cmd.Parameters.AddWithValue("@Sid", Sid); cmd.ExecuteNonQuery(); SqlDataAdapter adp = new SqlDataAdapter(cmd); adp.Fill(ds); conn.Close(); List CityDetails = new List(); foreach (DataRow DR in ds.Tables[0].Rows) { string Rid = DR["Rid"].ToString(); string RegionName = DR[" RegionName"].ToString(); CityDetails.Add(new CascadingDropDownNameValue(RegionName, Rid)); } return CityDetails.ToArray(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)