Click here to Skip to main content
15,895,370 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi i downloaded a sample of cascadeDropDown list that exist in asp.net site with Following path
http://www.asp.net/web-forms/tutorials/ajax-control-toolkit/cascadingdropdown/using-cascadingdropdown-with-a-database-cs[^]
but when the program run the drop down list is empty i cant find problem
anyone can help me
thank
the code is here :
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title></title>
</head>
<body style="height: 235px">
    <form id="form1"  runat="server">
   <asp:ScriptManager ID="asm" runat="server" />
    <div>
    Vendor: <asp:DropDownList ID="VendorsList" runat="server" /><br />
    Contacts: <asp:DropDownList ID="ContactsList" runat="server" /><br />
    </div>
    <CascadingDropDown ID="ccd1"  runat="server"
      ServicePath="CascadingDropdown1.cs.asmx" ServiceMethod="GetVendors" 
      TargetControlID="VendorsList" Category="VendorContact"
      PromptText="Select Vendor" />
    <CascadingDropDown ID="ccd2"  runat="server"
      ServicePath="CascadingDropdown1.cs.asmx" ServiceMethod="GetContactsForVendor"
      TargetControlID="ContactsList"  ParentControlID="VendorsList" Category="Contact" 
      PromptText="Select Contact" />
    </form>
</body>
</html>


and the web service code is here :
C#
using System.Web.Script.Services;
using AjaxControlToolkit;
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data.SqlClient;



/// <summary>
/// Summary description for WebService
/// </summary>
[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 WebService : System.Web.Services.WebService {
    [WebMethod]
    public CascadingDropDownNameValue[] GetContactsForVendor(string knownCategoryValues, string category)
    {
        int VendorID=1;
        StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        if (!kv.ContainsKey("Vendor") || !Int32.TryParse(kv["Vendor"], out VendorID))
        {
           // throw new ArgumentException("Couldn't find vendor.");
        };

        SqlConnection conn = new SqlConnection(
        "Data Source=KING-STARS;Initial Catalog=AdventureWorks;Integrated Security=True");
        conn.Open();
        SqlCommand comm = new SqlCommand(
          "SELECT Person.Contact.ContactID, FirstName, LastName FROM Person.Contact, Purchasing.VendorContact WHERE VendorID=@VendorID AND Person.Contact.ContactID=Purchasing.VendorContact.ContactID" , conn);
        comm.Parameters.AddWithValue("@VendorID", VendorID);
        SqlDataReader dr = comm.ExecuteReader();
        List<CascadingDropDownNameValue> l = new List<CascadingDropDownNameValue>();

        while (dr.Read())
        {
            l.Add(new CascadingDropDownNameValue(
              dr["FirstName"].ToString() + " " + dr["LastName"].ToString(), dr["ContactID"].ToString()));
        }
        conn.Close();
        return l.ToArray();
    }

    [WebMethod]
    public CascadingDropDownNameValue[] GetVendors(string knownCategoryValues, string category)
    {
        SqlConnection conn = new SqlConnection(
         "Data Source=KING-STARS;Initial Catalog=AdventureWorks;Integrated Security=True");
        conn.Open();
        SqlCommand comm = new SqlCommand(
          "SELECT TOP 25 VendorID, Name FROM Purchasing.Vendor",
          conn);
        SqlDataReader dr = comm.ExecuteReader();
        List<CascadingDropDownNameValue> l = new List<CascadingDropDownNameValue>();

        while (dr.Read())
        {
            l.Add(new CascadingDropDownNameValue(
              dr["Name"].ToString(),
              dr["VendorID"].ToString()));
        }
        conn.Close();
        return l.ToArray();
    }
    
}
Posted
Updated 14-Feb-12 7:17am
v8
Comments
behrad110 14-Feb-12 13:16pm    
may it happen because of difference version of visual studio ?
fjdiewornncalwe 14-Feb-12 14:25pm    
It could be. The link you have provided is targetted at Studio 2005, so the dotNet version being used is either 1.1 or 2.0.
If you are using Studio 2010, I would suggest that you target all your projects at dotNet 2.0 instead of dotNet 4.0 and then try again.
behrad110 14-Feb-12 15:11pm    
thanks for response but i wanna know how i can do it in vs2010. what thing is change in 2010 version.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900