CascadingDropDown我个人感觉有几个规则:
1. 需要配合xml
2. 需要配合两个方法:CascadingDropDown.ParseKnownCategoryValuesString和CascadingDropDown.QuerySimpleCascadingDropDownDocument
3. 似乎需要配合WebService
希望有人指出错误之处。
联动选择的下拉框最多的应用我想应该是地区的选择吧,估计每个web程序员都碰到过,下面来看atlas的解决方案:
前端代码Default.aspx:
<formid="form1"runat="server">
<asp:ScriptManagerID="ScriptManager1"runat="server"/>
<divclass="demoarea">
<divclass="demoheading">CascadingDropDown联动选择的下拉框</div>
<table>
<tr>
<td>国家</td>
<td><asp:DropDownListID="DropDownList1"runat="server"Width="170"/></td>
</tr>
<tr>
<td>省份</td>
<td><asp:DropDownListID="DropDownList2"runat="server"Width="170"/></td>
</tr>
<tr>
<td>城市</td>
<td><asp:DropDownListID="DropDownList3"runat="server"Width="170"AutoPostBack="true"
OnSelectedIndexChanged="DropDownList3_SelectedIndexChanged"/></td>
</tr>
</table>
<cc1:CascadingDropDownID="CascadingDropDown1"runat="server"TargetControlID="DropDownList1"
Category="Make"PromptText="Pleaseselectamake"LoadingText="[Loadingmakes...]"
ServicePath="CarsService.asmx"ServiceMethod="GetDropDownContents"/>
<cc1:CascadingDropDownID="CascadingDropDown2"runat="server"TargetControlID="DropDownList2"
Category="Model"PromptText="Pleaseselectamodel"LoadingText="[Loadingmodels...]"
ServiceMethod="GetDropDownContentsPageMethod"ParentControlID="DropDownList1"/>
<cc1:CascadingDropDownID="CascadingDropDown3"runat="server"TargetControlID="DropDownList3"
Category="Color"PromptText="Pleaseselectacolor"LoadingText="[Loadingcolors...]"
ServicePath="CarsService.asmx"ServiceMethod="GetDropDownContents"
ParentControlID="DropDownList2"/>
<asp:UpdatePanelID="UpdatePanel1"runat="server"UpdateMode="Conditional"RenderMode="inline">
<ContentTemplate>
<asp:LabelID="Label1"runat="server"Text="[您还没有选择]"/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTriggerControlID="DropDownList3"EventName="SelectedIndexChanged"/>
</Triggers>
</asp:UpdatePanel>
</div>
</form>
Default.aspx.cs
usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;
usingSystem.Web.Services;
usingAjaxControlToolkit;
publicpartialclass_Default:System.Web.UI.Page
...{
protectedvoidPage_Load(objectsender,EventArgse)
...{
}
protectedvoidTextBox1_TextChanged(objectsender,EventArgse)
...{
}
protectedvoidButton1_Click(objectsender,EventArgse)
...{
}
protectedvoidDropDownList3_SelectedIndexChanged(objectsender,EventArgse)
...{
//Getselectedvalues
stringmake=DropDownList1.SelectedItem.Text;
stringmodel=DropDownList2.SelectedItem.Text;
stringcolor=DropDownList3.SelectedItem.Text;
//Outputresultstringbasedonwhichvaluesarespecified
if(string.IsNullOrEmpty(make))
...{
Label1.Text="Pleaseselectamake.";
}
elseif(string.IsNullOrEmpty(model))
...{
Label1.Text="Pleaseselectamodel.";
}
elseif(string.IsNullOrEmpty(color))
...{
Label1.Text="Pleaseselectacolor.";
}
else
...{
Label1.Text=string.Format("您选择的地区是{0}{1}{2}。",color,make,model);
}
}
[WebMethod]
[System.Web.Script.Services.ScriptMethod]
publicstaticCascadingDropDownNameValue[]GetDropDownContentsPageMethod(stringknownCategoryValues,stringcategory)
...{
returnnewCarsService().GetDropDownContents(knownCategoryValues,category);
}
}
数据:
<?xmlversion="1.0"encoding="utf-8"?>
<CarsService>
<makename="中国">
<modelname="浙江">
<colorname="杭州"/>
<colorname="宁波"/>
<colorname="金华"/>
</model>
<modelname="江苏">
<colorname="南京"/>
<colorname="苏州"/>
</model>
<modelname="福建">
<colorname="福州"/>
<colorname="厦门"/>
</model>
</make>
<makename="美国">
<modelname="A4">
<colorname="Azure"/>
<colorname="LightAzure"/>
<colorname="DarkAzure"/>
</model>
<modelname="S4"value="S4(value)">
<colorname="Silver"value="Silver(value)"/>
<colorname="Metallic"value="Metallic(value)"/>
</model>
<modelname="A6"value="A6(value)">
<colorname="Cyan"value="Cyan(value)"/>
</model>
</make>
<makename="韩国">
<modelname="3series"value="3series(value)">
<colorname="Blue"value="Blue(value)"/>
<colorname="SkyBlue"value="SkyBlue(value)"/>
<colorname="RacingBlue"value="RacingBlue(value)"/>
</model>
<modelname="5series"value="5series(value)">
<colorname="Yellow"value="Yellow(value)"/>
<colorname="Banana"value="Banana(value)"/>
</model>
<modelname="7series"value="7series(value)">
<colorname="Brown"value="Brown(value)"/>
</model>
</make>
</CarsService>
WebService代码:
//(c)CopyrightMicrosoftCorporation.
//ThissourceissubjecttotheMicrosoftPermissiveLicense.
//Seehttp://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
//Allotherrightsreserved.
usingSystem;
usingSystem.Collections.Specialized;
usingSystem.Web;
usingSystem.Web.Services;
usingSystem.Xml;
/**////<summary>
///HelperwebserviceforCascadingDropDownsample
///</summary>[WebService(Namespace="http://tempuri.org/")]
[WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
publicclassCarsService:WebService
...{
//Membervariables
privatestaticXmlDocument_document;
privatestaticobject_lock=newobject();
//wemakethesepublicstaticsjustsowecancallthemfromexternallyforthe
//pagemethodcall
publicstaticXmlDocumentDocument
...{
get
...{
lock(_lock)
...{
if(_document==null)
...{
//ReadXMLdatafromdisk
_document=newXmlDocument();
_document.Load(HttpContext.Current.Server.MapPath("~/App_Data/CarsService.xml"));
}
}
return_document;
}
}
publicstaticstring[]Hierarchy
...{
get...{returnnewstring[]...{"make","model"};}
}
/**////<summary>
///Constructortoinitializemembers
///</summary>
publicCarsService()
...{
}
/**////<summary>
///Helperwebservicemethod
///</summary>
///<paramname="knownCategoryValues">privatestorageformatstring</param>
///<paramname="category">categoryofDropDownListtopopulate</param>
///<returns>listofcontentitems</returns>
[WebMethod]
publicAjaxControlToolkit.CascadingDropDownNameValue[]GetDropDownContents(stringknownCategoryValues,stringcategory)
...{
//Getadictionaryofknowncategory/valuepairs
StringDictionaryknownCategoryValuesDictionary=AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
//Performasimplequeryagainstthedatadocument
returnAjaxControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(Document,Hierarchy,knownCategoryValuesDictionary,category);
}
}
效果如下:
分享到:
相关推荐
:musical_note: Altas-Notas 我基于Firebase服务的Spotify版本 :joystick: 安装及使用方法从Zip导出项目并导入完整文件夹 :laptop: 进步▰▱▱▱▱▱▱▱▱▱10% :camera: 屏幕截图目前没有照片
自己写的第2个 ajax例子 3联动+无刷新分页(no altas) 无刷新分页 有点bug 只需要把 js/xmlhttp.js 里面的 的标签 里的属性 +一个 单引号 就行了 App_data下的my51aspx.mdf为Sql数据库文件,附加即可 数据库操作...
圣殿祭司 的 开发详解-使用C#>里面的讲解AJAX的第5,6两张。比较具有实用性。看完后。二分钟就能写出局部更新的网页来。
本文介绍了Ajax的基本工作原理,并实现了网上聊天系统的基本功能
Ajax三级联动和无刷新分页源码 数据库是用的 51aspx的数据库(含中国完整省市区的数据) 自己写的第2个 ajax例子 3联动+无刷新分页(no altas) 无刷新分页
unity3d 日历控件,ngui的altas丢失了,需要自己添加u2b
Hashicorp Atlas 教程示例代码
Altas 学习指南........
altas非常有用的资源,怎样使用atlas客户端更新,真正的"ajax"客户端技术
altas网上聊天系统--本文介绍了ajax的基本工作原理,并实现了网上聊天系统的功能!
MYSQL ALTAS配置手册
AJAX结合Asp.NET开发的经典事例,可直接运行或者更改代码来深入学习.
Altas学习指南,希望对大家有帮助
使用python对plist altas进行拆分,还原成原来的小图
改良后的python版的spine中图片资源分割,支持图片旋转,原来版本不支持图片旋转,亲手写的
Silvaco Atlas User's Manual Silvaco Altas用户手册(英文版)
Atlas插件excel,DynamicAX 2012 插件,Atlas插件excel,DynamicAX 2012 插件