ASP.NET / C# - Ajax Cascading DropDown - Second DDL Not Populating
<p>I'm creating a simple web form which is driven by a cascading DDL. The first list populates from a list of given values; the second is populated by an SQL query with the selected value in the first DDL acting as the parameter for the second's query. Seems simple enough from piecing together examples found online, but, unfortunately, the second DDL is not populating at all. I've checked that the query itself is fine and will populate when the WHERE clause / parameter are eliminated.</p>

<p>Here's the code:</p>

<p>C#</p>

<pre><code>using AjaxControlToolkit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace Web_Form___Chart_Review
{
/// &lt;summary&gt;
/// Summary description for ProgramCS
/// &lt;/summary&gt;
[WebService(Namespace = "http://tempuri.org")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 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 ProgramCS : System.Web.Services.WebService
{
    List&lt;Division&gt; division = new List&lt;Division&gt;();
    [WebMethod]
    public CascadingDropDownNameValue[] GetDivision(string knownCategoryValues, string category)
    {
        division.Add(new Division { DivID = "MH", Name = "Mental Health" });
        division.Add(new Division { DivID = "SUD", Name = "Substance Use Disorder" });
        division.Add(new Division { DivID = "GAM", Name = "Gambling" });
        division.Add(new Division { DivID = "%", Name = "LMP" });
        List&lt;CascadingDropDownNameValue&gt; l = new List&lt;CascadingDropDownNameValue&gt;();
        var x = from c in division select c;
        foreach (Division divisions in x)
        {
            l.Add(new CascadingDropDownNameValue(divisions.Name,divisions.DivID));

        }
        return l.ToArray();
    }

    [WebMethod]
    public CascadingDropDownNameValue[] GetSite(string knownCategoryValues, string category)
    {
        string sel_division = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)["DivID"];
        string query = string.Format("SELECT DISTINCT [SiteName],[Site] FROM ChartReview.dbo.vw_ProgramList WHERE [Category] like '{0}'",sel_division);
        List&lt;CascadingDropDownNameValue&gt; sites = GetData(query);
        return sites.ToArray();
    }

    public class Division
    {
        public string DivID {get;set;}
        public string Name {get;set;}
    }

    private List&lt;CascadingDropDownNameValue&gt; GetData(string query)
    {
        string conString = ConfigurationManager.ConnectionStrings["SqlServer"].ConnectionString;
        SqlCommand cmd = new SqlCommand(query);
        List&lt;CascadingDropDownNameValue&gt; values = new List&lt;CascadingDropDownNameValue&gt;();
        using (SqlConnection con = new SqlConnection(conString))
        {
            con.Open();
            cmd.Connection = con;
            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    values.Add(new CascadingDropDownNameValue
                    {
                        name = reader[0].ToString(),
                        value = reader[1].ToString()
                    });
                }
                reader.Close();
                con.Close();
                return values;
            }
        }
    }

}
}
</code></pre>

<p>And the HTML:</p>

<pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Web_Form___Chart_Review.Default" EnableEventValidation="false" %&gt;
&lt;%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %&gt;

&lt;!DOCTYPE html&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head runat="server"&gt;
&lt;title&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form id="form1" runat="server"&gt;
    &lt;asp:ScriptManager ID="asm" runat="server"&gt;&lt;/asp:ScriptManager&gt;
&lt;div&gt;
        For which division are you creating a tally?&lt;br /&gt;
    &lt;asp:DropDownList ID="ddlSelectDivision" runat="server"&gt;&lt;/asp:DropDownList&gt;
    &lt;ajaxToolkit:CascadingDropDown ID="ddlSelectDivision_CascadingDropDown" runat="server" TargetControlID="ddlSelectDivision" ServicePath="ProgramCS.asmx" ServiceMethod="GetDivision" Category="Division" PromptText="Select Division" SelectedValue="MH" PromptValue="MH" LoadingText="Loading..." /&gt;
    &lt;br /&gt;
    &lt;asp:DropDownList ID="ddlSelectSite" runat="server"&gt;&lt;/asp:DropDownList&gt;
    &lt;ajaxToolkit:CascadingDropDown ID="ddlSelectSite_CascadingDropDown" runat="server" TargetControlID="ddlSelectSite" ServicePath="ProgramCS.asmx" ServiceMethod="GetSite" Category="Site" PromptText="Select Site" PromptValue="" LoadingText="Loading..." /&gt;



    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>