1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using AjaxControlToolkit;
using System.Collections.Specialized;
[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 AjaxCascadingDropDown : System.Web.Services.WebService
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DatabaseConnectionString1"].ToString());
public AjaxCascadingDropDown () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public CascadingDropDownNameValue[] GetVendors(string knownCategoryValues, string category)
{
con.Open();
SqlCommand comm = new SqlCommand("SELECT * FROM UTILISATEUR",con);
SqlDataReader dr = comm.ExecuteReader();
List<CascadingDropDownNameValue> l = new List<CascadingDropDownNameValue>();
while (dr.Read())
{
l.Add(new CascadingDropDownNameValue(dr["NOM_COMPLET_UTILISATEUR"].ToString(),
dr["ID_UTILISATEUR"].ToString()));
}
con.Close();
return l.ToArray();
}/*
[WebMethod]
public CascadingDropDownNameValue[] FetchStates(string knownCategoryValues, string category)
{
int countryId;
StringDictionary strCountries = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
countryId = Convert.ToInt32(strCountries["Country"]);
con.Open();
SqlCommand cmd = new SqlCommand("select * from Tbl_State where Country_ID_Fk=@CountryID", con);
cmd.Parameters.AddWithValue("@CountryID", countryId);
cmd.ExecuteNonQuery();
SqlDataAdapter dastate = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
dastate.Fill(ds);
con.Close();
List<CascadingDropDownNameValue> states = new List<CascadingDropDownNameValue>();
foreach (DataRow dtRow in ds.Tables[0].Rows)
{
string StateID = dtRow["State_Id_Pk"].ToString();
string StateName = dtRow["State_Name"].ToString();
states.Add(new CascadingDropDownNameValue(StateName, StateID));
}
return states.ToArray();
}
[WebMethod]
public CascadingDropDownNameValue[] FetchCities(string knownCategoryValues, string category)
{
int stateId;
StringDictionary strStates = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
stateId = Convert.ToInt32(strStates["State"]);
con.Open();
SqlCommand cmd = new SqlCommand("select * from Tbl_City where State_ID_Fk=@StateID", con);
cmd.Parameters.AddWithValue("@StateID", stateId);
cmd.ExecuteNonQuery();
SqlDataAdapter daregion = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
daregion.Fill(ds);
con.Close();
List<CascadingDropDownNameValue> cities = new List<CascadingDropDownNameValue>();
foreach (DataRow dtRow in ds.Tables[0].Rows)
{
string RegionID = dtRow["City_id_pk"].ToString();
string RegionName = dtRow["City_Name"].ToString();
cities.Add(new CascadingDropDownNameValue(RegionName, RegionID));
}
return cities.ToArray();
} */
} |
Partager