[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 DropdownWebService : System.Web.Services.WebService { [WebMethod] public CascadingDropDownNameValue[] BindCountrydropdown(string knownCategoryValues, string category) { SqlConnection concountry = new SqlConnection(ConfigurationManager.ConnectionStrings["cnnstring"].ConnectionString); concountry.Open(); SqlCommand cmdcountry = new SqlCommand("select * from Country", concountry); SqlDataAdapter dacountry = new SqlDataAdapter(cmdcountry); cmdcountry.ExecuteNonQuery(); DataSet dscountry = new DataSet(); dacountry.Fill(dscountry); concountry.Close(); List<cascadingdropdownnamevalue> countrydetails = new List<cascadingdropdownnamevalue>(); foreach (DataRow dtrow in dscountry.Tables[0].Rows) { string CountryID = dtrow["CountryID"].ToString(); string CountryName = dtrow["CountryName"].ToString(); countrydetails.Add(new CascadingDropDownNameValue(CountryName, CountryID)); } return countrydetails.ToArray(); } [WebMethod] public CascadingDropDownNameValue[] BindStatedropdown(string knownCategoryValues, string category) { int CountryID; StringDictionary countrydetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); CountryID = Convert.ToInt32(countrydetails["Country"]); SqlConnection constate = new SqlConnection(ConfigurationManager.ConnectionStrings["cnnstring"].ConnectionString); constate.Open(); SqlCommand cmdstate = new SqlCommand("select * from State where CountryID=@CountryID", constate); cmdstate.Parameters.AddWithValue("@CountryID", CountryID); cmdstate.ExecuteNonQuery(); SqlDataAdapter dastate = new SqlDataAdapter(cmdstate); DataSet dsstate = new DataSet(); dastate.Fill(dsstate); constate.Close(); List<cascadingdropdownnamevalue> statedetails = new List<cascadingdropdownnamevalue>(); foreach (DataRow dtstaterow in dsstate.Tables[0].Rows) { string stateID = dtstaterow["StateID"].ToString(); string statename = dtstaterow["StateName"].ToString(); statedetails.Add(new CascadingDropDownNameValue(statename, stateID)); } return statedetails.ToArray(); } [WebMethod] public CascadingDropDownNameValue[] BindRegiondropdown(string knownCategoryValues, string category) { int stateID; StringDictionary statedetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); stateID = Convert.ToInt32(statedetails["State"]); SqlConnection conregion = new SqlConnection(ConfigurationManager.ConnectionStrings["cnnstring"].ConnectionString); conregion.Open(); SqlCommand cmdregion = new SqlCommand("Select * from Region where StateID=@StateID", conregion); cmdregion.Parameters.AddWithValue("@StateID", stateID); cmdregion.ExecuteNonQuery(); SqlDataAdapter daregion = new SqlDataAdapter(cmdregion); DataSet dsregion = new DataSet(); daregion.Fill(dsregion); conregion.Close(); List<cascadingdropdownnamevalue> regiondetails = new List<cascadingdropdownnamevalue>(); foreach (DataRow dtregionrow in dsregion.Tables[0].Rows) { string regionID = dtregionrow["RegionID"].ToString(); string regionname = dtregionrow["RegionName"].ToString(); regiondetails.Add(new CascadingDropDownNameValue(regionname, regionID)); } return regiondetails.ToArray(); } }
try..catch
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)