I have 2 dropdown boxes with the CascadingDropDown ajax extension attached to them, they are reading from an xml file not database. I dont get an error but my first dropdown bar shows "Please select an option" ie my prompt text, but not the xml options... my xml is set out correctly (ie the same hierarchical XML layout as the sample ajax website). Any ideas why this isnt showing me options but doesnt error? thanks in advance John
i feel as though i should explain more. Basically ive got an xml file layed out like :
<?xml version="1.0" encoding="utf-8" ?>
<GroupService>
<Group name="One">
<SubGroup name="One" />
<SubGroup name="Two" />
</Group>
</Service>
Based on two categorys. I have two drop down boxes with the code :
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="DropDownList1"
Category="Group" PromptText="Please select a Type" LoadingText="[Loading makes...]"
ServicePath="GroupsService.asmx" ServiceMethod="GetDropDownContents" /
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
<ajaxToolkit:CascadingDropDown ID="CascadingDropDown2" runat="server" TargetControlID="DropDownList2"
Category="SubGroup" PromptText="Please select a Group Type" LoadingText="[Loading models...]"
ServiceMethod="GroupsService.asmx" ParentControlID="DropDownList1" /
The ServiceMethod is correctly referance.Now my webservice is :
using System;
using System.Web;
using System.Collections;
using System.Collections.Specialized;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;
/// <summary>
/// Summary description for GroupsService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class GroupsService : System.Web.Services.WebService
{
// Member variables
private static XmlDocument _document;
private static object _lock = new object();
// we make these public statics just so we can call them from externally for the
// page method call
public static XmlDocument Document
{
get
{
lock (_lock)
{
if (_document == null)
{
// Read XML data from disk
_document = new XmlDocument();
_document.Load(HttpContext.Current.Server.MapPath("~/App_Data/GroupsService.xml"));
}
}
return _document;
}
}
public static string[] Hierarchy
{
get { return new string[] {"Group", "SubGroup" }; }
}
public GroupsService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetDropDownContents(string knownCategoryValues, string category)
{
// Get a dictionary of known category/value pairs
StringDictionary knownCategoryValuesDictionary = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
// Perform a simple query against the data document
return AjaxControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(Document, Hierarchy, knownCategoryValuesDictionary, category);
}
}
It doesnt give me an error and it says its loading but then no items are shown, has anyone else had this error? thanks in advance John
did a little bit of work on this and saw in the sample website i got with the ajax download the hierarchy is :
public static string[] Hierarchy
{
get { return new string[] { "make", "model" }; }
}
it misses out the last value ie color of the colours. so i change mine to :
public static string[] Hierarchy
{
get { return new string[] { "Group" }; }
}
ie got rid of the last valuein the hierarchy, but still no luck, does anyone know if it is possible to do this from 2 dropdown boxes rather than 3? if so can someone point me in the right direction? thanks in advance John
Hi,
Please refer to thisthread for how to use a XML document with different format.
Or you can change attribute "name" to "value" .
I have had the same issue all day.. Finally noticing the only difference between mine and the sample was case, I tried making the xml attribute strings names lower case ie.. <group> <subgroup> and made sure the heirarchy property was also lower case and they now populate.
Hope this helps
No comments:
Post a Comment