CascadingDropDown Demonstration

本文介绍了一种名为 CascadingDropDown 的 ASP.NET AJAX 组件,该组件允许在一个下拉列表选择变化时自动填充一系列下拉列表。文章详细介绍了 CascadingDropDown 的工作原理及其属性配置,并提供了使用示例。
 
CascadingDropDown Demonstration
Make Please select a makeAcuraAudiBMW 
Model Please select a modelIntegraRLTL 
Color Please select a colorGreenSea GreenPale Green 
 
You have chosen a Green Acura Integra. Nice car!
 
CascadingDropDown Description
CascadingDropDown is an ASP.NET AJAX extender that can be attached to an ASP.NET DropDownList control to get automatic population of a set of DropDownList controls. Each time the selection of one the DropDownList controls changes, the CascadingDropDown makes a call to a specified web service to retrieve the list of values for the next DropDownList in the set.
 
 
CascadingDropDown enables a common scenario in which the contents of one list depends on the selection of another list and does so without having to embed the entire data set in the page or transfer it to the client at all. All the logic about the contents of the set of DropDownList controls lives on the server in a web service. This web service can use any suitable method for storing and looking up the relevant data. The sample web service used here reads the data set from a simple hierarchical XML data file. The sample data file shows that the DropDownList items can have distinct names and value (values are optional in the sample). There is also a walkthrough showing how to use a CascadingDropDown with a database.
 
CascadingDropDown Properties
The control above is initialized with this code. The italic properties are optional:
 
<ajaxToolkit:CascadingDropDown ID="CDD1" runat="server"
    TargetControlID="DropDownList2"
    Category="Model"
    PromptText="Please select a model"
    LoadingText="[Loading models...]"
    ServicePath="CarsService.asmx"
    ServiceMethod="GetDropDownContents"
    ParentControlID="DropDownList1"
SelectedValue="SomeValue" />
 
l        TargetControlID - The ID of the DropDownList to populate.
l        Category - The name of the category this DropDownList represents.
l        PromptText - Optional text with which to prompt the user when this DropDownList is empty.
l        LoadingText - Optional text to display while the data for the DropDownList is being loaded.
l        ServicePath - Path to a web service that returns the data used to populate the DropDownList. This property should be left null if ServiceMethod refers to a page method. The web service should be decorated with the System.Web.Script.Services.ScriptService attribute.
l        ServiceMethod - Web service method that returns the data used to populate the DropDownList. The signature of this method must match the following:
 
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public CascadingDropDownNameValue[] GetDropDownContents(
       string knownCategoryValues, string category) { ... }
 
Note that you can replace "GetDropDownContents" with a naming of your choice, but the return type and parameter name and type must exactly match, including case.
l        ContextKey - User/page specific context provided to an optional overload of the web method described by ServiceMethod/ServicePath. If the context key is used, it should have the same signature with an additional parameter named contextKey of type string:
l
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public CascadingDropDownNameValue[] GetDropDownContents(
       string knownCategoryValues, string category, string contextKey) { ... }
 
Note that you can replace "GetDropDownContents" with a name of your choice, but the return type and parameter name and type must exactly match, including case.
l        UseContextKey - Whether or not the ContextKey property should be used. This will be automatically enabled if the ContextKey property is ever set (on either the client or the server). If the context key is used, it should have the same signature with an additional parameter named contextKey of type string (as described above).
l        ParentControlID - Optional ID of the parent DropDownList that controls the contents of this DropDownList.
l        SelectedValue - Optional value to select by default. This needs to exactly match the string representation of a value in the DropDownList.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值