problème avec CascadingDropDown
salut mes amis j'utilisa des CascadingDropDowns (depuis une base de données)
mais quand j'execute je trouve que ma liste est vide
voilà le .aspx
Code:
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
| <%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeFile="ajax.aspx.cs" Inherits="ajax" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<fieldset style="width:340px;">
<legend>Fill Country,State and City DropDownList in asp.net</legend>
<table>
<tr>
<td width="40%">Select Country:</td>
<td>
<asp:DropDownList ID="ddlCountry" runat="server"
Width="187px" AutoPostBack="True"></asp:DropDownList>
</td>
<ASP:CascadingDropDown ID="ccd2" runat="server"
ServicePath="AjaxCascadingDropDown.asmx" ServiceMethod="GetVendors"
TargetControlID="ddlCountry"
Category="utilisateur"
PromptText="Select Contact" ></asp:CascadingDropDown>
</tr>
<tr>
<td>Select State:</td>
<td>
<asp:DropDownList ID="ddlState" runat="server"
Width="187px"> </asp:DropDownList>
<asp:CascadingDropDown ID="csdState" runat="server"
ParentControlID="ddlCountry"
Category="State"
TargetControlID="ddlState"
PromptText="-- Select State --"
LoadingText="[Loading States...]"
ServiceMethod="FetchStates"
ServicePath="AjaxCascadingDropDown.asmx" />
</td>
</tr>
<tr>
<td>Select City:</td>
<td>
<asp:DropDownList ID="ddlCity" runat="server" Width="187px" AutoPostBack="True"
></asp:DropDownList>
<asp:CascadingDropDown ID="csdCity" runat="server"
ParentControlID="ddlState"
Category="City"
TargetControlID="ddlCity"
PromptText="-- Select City --"
LoadingText="[Loading Cities...]"
ServiceMethod="FetchCities"
ServicePath="AjaxCascadingDropDown.asmx">
</asp:CascadingDropDown>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblStatus" runat="server" Text="" style="color: #006600"></asp:Label>
</td>
</tr>
</table>
</fieldset>
</div>
</form>
</body>
</html> |
web service
Code:
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();
} */
} |
merci d'avance