Here is simple VB example of the AjaxToolkit's CascadingDropDown extender. For this example I use the CarsService.Xml found in the AjaxToolkits sample site. The xml file needs to be placed in the App_data directory
Here is the Pages Html
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="sm1" EnablePageMethods="true" runat="server">
</asp:ScriptManager>
<table>
<tr>
<td>
Make
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" Width="341px">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
Model
</td>
<td>
<asp:DropDownList ID="DropDownList2" runat="server" Width="341px">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
Color
</td>
<td>
<asp:DropDownList ID="DropDownList3" runat="server" Width="341px">
</asp:DropDownList>
</td>
</tr>
</table>
</div>
<cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="DropDownList1"
Category="Make" PromptText="Please select a make" LoadingText="[Loading makes...]" ServiceMethod="GetDropDownContents">
</cc1:CascadingDropDown>
<cc1:CascadingDropDown ID="CascadingDropDown2" runat="server" TargetControlID="DropDownList2"
Category="Model" PromptText="Please select a model" LoadingText="[Loading models...]"
ServiceMethod="GetDropDownContents" ParentControlID="DropDownList1">
</cc1:CascadingDropDown>
<cc1:CascadingDropDown ID="CascadingDropDown3" runat="server" TargetControlID="DropDownList3"
Category="Color" PromptText="Please select a color" LoadingText="[Loading colors...]"
ServiceMethod="GetDropDownContents"
ParentControlID="DropDownList2">
</cc1:CascadingDropDown>
</form>
</body>
</html>
In the code behind I am using a shared class so I only have to load the xml document once.
Imports System.Xml
Partial Class _Default
Inherits System.Web.UI.Page
<System.Web.Services.WebMethod()> _
<System.Web.Script.Services.ScriptMethod()> _
Public Shared Function GetDropDownContents(ByVal knownCategoryValues As String, ByVal category As String) As AjaxControlToolkit.CascadingDropDownNameValue()
Dim knownCategoryValuesDictionary As StringDictionary = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)
Return AjaxControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(CarsInfo.Document, CarsInfo.Hierarchy, knownCategoryValuesDictionary, category)
End Function
End Class
Public Class CarsInfo
Private Shared _Doc As XmlDocument
Private Shared _load As Boolean = True
Public Shared ReadOnly Property Document() As XmlDocument
Get
If _load Then
_Doc = New XmlDocument
_Doc.Load(HttpContext.Current.Server.MapPath("~/App_Data/CarsService.xml"))
_load = False
End If
Return _Doc
End Get
End Property
Public Shared ReadOnly Property Hierarchy() As String()
Get
Return New String() {"make", "model"}
End Get
End Property
End Class