In the previous article we discussed about the properties of Cascading Dropdown extender control, now here we will learn how to use the XML data document to populate the data in associated dropdown controls of ASP.Net. Cascading Dropdown web method consumes the very simple hierarchy of XML document to populate the first dropdown and then other dropdown according to the change in selected index of first dropdown control.
In this example code for Cascading Dropdown extender control we have generated a XML document using Categories and Products table of Northwind database. The cascading dropdown extender controls used in this example will explain the functionality to load the first dropdown control with categories and on selected index change it will populate the second dropdown control with corresponding product names.
Above example shows the HTML code for CascadingDropdown Extender control with Web Service Property. Following is the web service method to populate the dropdown controls:
StringDictionary knownCategoryValuesDictionary = AjaxControlToolkit. CascadingDropDown. ParseKnownCategoryValuesString(knownCategoryValues);
return AjaxControlToolkit.CascadingDropDown. QuerySimpleCascadingDropDownDocument(_xmlDocument, documentHierarchy, knownCategoryValuesDictionary, category); }
Please note that you can change the name of web method but you have to use the same name and datatype for the web method parameters and return type as used in the sample web service provided with this article. E.g.:
public AjaxControlToolkit.CascadingDropDownNameValue[] GetDropDownContents(string knownCategoryValues, string category)
You have to add EnableEventValidation="false" in <% @Page %> header section of your ASP.Net web page to enable the AsynchronousPostback trigger of UpdatePanel.
Download the free sample code for cascading dropdown extender control with Northwind.xml data document and cascadingwebservice.asmx here...
ajax cascading dropdown xml.zip (5.86 kb)
Be the first to rate this post
Tags: asp.net 2.0, ajax, ajax cascading dropdown control, asp.net ajax control toolkit, cascading dropdown extender, ajax cascading dropdown xml, ajax cascading dropdown database, ajax cascading dropdown web service
10/11/2008 3:27:55 AM