Atlas学习手记(12):使用CascadingDropDown控件
2008-03-25 12:10
447 查看
CascadingDropDown通常叫作级联下拉菜单,本文将通过读取Northwind数据库中的Emplyee、Order、OrderDatail信息作为示例,来展示一下它的使用。
主要内容
1.CascadingDropDown控件介绍
2.从数据库读取数据并填充CascadingDropDown
一.CascadingDropDown控件介绍
CascadingDropDown通常叫作级联下拉菜单,本文将通过读取Northwind数据库中的Emplyee、Order、OrderDatail信息作为示例,来展示一下它的使用。示例代码如下:
<atlasToolkit:CascadingDropDown ID="CDD1" runat="server">
<atlasToolkit:CascadingDropDownProperties
TargetControlID="DropDownList2"
Category="Model"
PromptText="Please select a model"
LoadingText="[Loading models]"
ServicePath="CarsService.asmx"
ServiceMethod="GetDropDownContents"
ParentControlID="DropDownList1"
SelectedValue="SomeValue">
</atlasToolkit:CascadingDropDownProperties>
</atlasToolkit:CascadingDropDown>
对于CascadingDropDown需要为它添加CascadingDropDownProperties,有多少个下拉列表,就添加几个CascadingDropDownProperties,主要属性如下:
二.从数据库读取数据并填充CascadingDropDown
下面用读取Northwind数据库中的Emplyee、Order、OrderDatail信息,看一个完整的示例。在新建一个Web Site后,先在页面的头部加上:
<div>
<h3>
Employee:
<asp:DropDownList ID="ddlEmployees" runat="server" /><br /><br />
Order:
<asp:DropDownList ID="ddlOrders" runat="server" /><br /><br />
Detail:
<asp:DropDownList ID="ddlOrderDetails" runat="server" />
</h3>
</div>
下面我们添加一个Northwind.asmx的Web Service,编写相关的Web Method:
[WebMethod]
public CascadingDropDownNameValue[] GetEmployees(
string knownCategoryValues, string category)
using System.Web;
using System.Collections;
using System.Configuration;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web.Services;
using System.Web.Services.Protocols;
using AtlasControlToolkit;
using System.Data;
using System.Data.SqlClient;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=RJ-097;User ID=sa;Password=sa;Initial Catalog=Northwind" providerName="System.Data.SqlClient"/>
</connectionStrings>
这时我们再添加CascadingDropDown控件,设置它的属性如下:
<atlasToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server">
<atlasToolkit:CascadingDropDownProperties Category="Employee" ParentControlID=""
PromptText="Select Employee" SelectedValue="" ServiceMethod="GetEmployees" ServicePath="Northwind.asmx"
TargetControlID="ddlEmployees" />
<atlasToolkit:CascadingDropDownProperties Category="Order" ParentControlID="ddlEmployees"
PromptText="Select Order" SelectedValue="" ServiceMethod="GetOrdersByEmployee"
ServicePath="Northwind.asmx" TargetControlID="ddlOrders" />
<atlasToolkit:CascadingDropDownProperties Category="OrderDetail" ParentControlID="ddlOrders"
PromptText="Select OrderDetail" SelectedValue="" ServiceMethod="GetDetailsByOrder"
ServicePath="Northwind.asmx" TargetControlID="ddlOrderDetails" />
</atlasToolkit:CascadingDropDown>
至此,大功告成。运行后效果如下:
选择:
完整示例下载
主要内容
1.CascadingDropDown控件介绍
2.从数据库读取数据并填充CascadingDropDown
一.CascadingDropDown控件介绍
CascadingDropDown通常叫作级联下拉菜单,本文将通过读取Northwind数据库中的Emplyee、Order、OrderDatail信息作为示例,来展示一下它的使用。示例代码如下:
<atlasToolkit:CascadingDropDown ID="CDD1" runat="server">
<atlasToolkit:CascadingDropDownProperties
TargetControlID="DropDownList2"
Category="Model"
PromptText="Please select a model"
LoadingText="[Loading models]"
ServicePath="CarsService.asmx"
ServiceMethod="GetDropDownContents"
ParentControlID="DropDownList1"
SelectedValue="SomeValue">
</atlasToolkit:CascadingDropDownProperties>
</atlasToolkit:CascadingDropDown>
对于CascadingDropDown需要为它添加CascadingDropDownProperties,有多少个下拉列表,就添加几个CascadingDropDownProperties,主要属性如下:
属性 | 说明 |
TargetControlID | 指定要扩展的DropDownList的ID |
Category | DropDownList表示的类别名称,在WebMethod中会用到 |
PromptText | 没有选择时显示的文字 |
LoadingText | 加载数据时显示的文字 |
ServicePath | 获取数据的Web Service,为每个DropDownList都要指定 |
ServiceMethod | 获取数据的Web Method |
ParentControlID | 要扩展的DropDownList的父控件ID |
SelectedValue | 默认的选择项的值 |
下面用读取Northwind数据库中的Emplyee、Order、OrderDatail信息,看一个完整的示例。在新建一个Web Site后,先在页面的头部加上:
<div>
<h3>
Employee:
<asp:DropDownList ID="ddlEmployees" runat="server" /><br /><br />
Order:
<asp:DropDownList ID="ddlOrders" runat="server" /><br /><br />
Detail:
<asp:DropDownList ID="ddlOrderDetails" runat="server" />
</h3>
</div>
下面我们添加一个Northwind.asmx的Web Service,编写相关的Web Method:
[WebMethod]
public CascadingDropDownNameValue[] GetEmployees(
string knownCategoryValues, string category)
using System.Web;
using System.Collections;
using System.Configuration;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web.Services;
using System.Web.Services.Protocols;
using AtlasControlToolkit;
using System.Data;
using System.Data.SqlClient;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=RJ-097;User ID=sa;Password=sa;Initial Catalog=Northwind" providerName="System.Data.SqlClient"/>
</connectionStrings>
这时我们再添加CascadingDropDown控件,设置它的属性如下:
<atlasToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server">
<atlasToolkit:CascadingDropDownProperties Category="Employee" ParentControlID=""
PromptText="Select Employee" SelectedValue="" ServiceMethod="GetEmployees" ServicePath="Northwind.asmx"
TargetControlID="ddlEmployees" />
<atlasToolkit:CascadingDropDownProperties Category="Order" ParentControlID="ddlEmployees"
PromptText="Select Order" SelectedValue="" ServiceMethod="GetOrdersByEmployee"
ServicePath="Northwind.asmx" TargetControlID="ddlOrders" />
<atlasToolkit:CascadingDropDownProperties Category="OrderDetail" ParentControlID="ddlOrders"
PromptText="Select OrderDetail" SelectedValue="" ServiceMethod="GetDetailsByOrder"
ServicePath="Northwind.asmx" TargetControlID="ddlOrderDetails" />
</atlasToolkit:CascadingDropDown>
至此,大功告成。运行后效果如下:
选择:
完整示例下载
相关文章推荐
- Atlas学习手记(12):使用CascadingDropDown控件
- Atlas学习手记(12):使用CascadingDropDown控件
- Atlas学习手记(12):使用CascadingDropDown控件
- Atlas学习手记(4):使用AutoComplete Extender实现自动完成功能
- Atlas学习手记(21):使用行为增强用户界面(一):Click Behavior
- Atlas学习手记(10):使用AlwaysVisibleControl Extender
- Atlas学习手记(16):使用PasswordStrength检测密码强度
- Atlas学习手记(21):使用行为增强用户界面(一):Click Behavior
- Atlas学习手记(6):使用Atlas UpdateProgress控件
- Atlas学习手记(10):使用AlwaysVisibleControl Extender
- Atlas学习手记(6):使用Atlas UpdateProgress控件
- Atlas学习手记(13):使用TextBoxWatermark为TextBox加上水印效果
- Atlas学习手记(15):使用RoundedCorners为控件加上圆角效果
- Atlas学习手记(17):使用FilteredTextBox过滤字符
- Atlas学习手记(22):使用行为增强用户界面(二):Floating Behavior
- Atlas学习手记(7):使用DragOverlayExtender实现拖放功能
- Atlas学习手记(14):使用ToggleButton Extender来装扮CheckBox
- Atlas学习手记(16):使用PasswordStrength检测密码强度
- Atlas学习手记(5):使用服务端定时控件TimerControl
- Atlas学习手记(22):使用行为增强用户界面(二):Floating Behavior