| 订阅 | 在线投稿
分享
 
 
 

asp.net AJAX中的CascadingDropDown控件使用心得

2008-12-13 08:23:46 编辑來源:互联网 国际版 评论
 
 
本文为【asp.net AJAX中的CascadingDropDown控件使用心得】的汉字拼音对照版显示拼音
  jibenzenmeyongzhelijiubuluosuolewangshangyouhenduowenzhangjieshaobaokuoasp.netnabianyeyoushilikeyixiazaizhelichongdianshuoshuoCategoryzhegeshuxingjiruhegoujianwebserviceCascadingDropDowndehewebservicepeihe使shiyongcaixingxiankanyemiankongjiandaimaview plaincopy to clipboardprint?

  <!--xialaliebiaokongjian-->

  <asp:DropDownList ID="ddlRootClass" runat="server"></asp:DropDownList> 

  <asp:DropDownList ID="ddlSubClass" runat="server"></asp:DropDownList> 

  <!--duiyingdeCascadingDropDownkongjian-->

  <cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" LoadingText="jiazaizhong" PromptText="qingxuanze"

  ServiceMethod="ClientTypeRootList" ServicePath="/Common/ClientTypeCascadingDropDown.asmx"

  TargetControlID="ddlRootClass" Category="RootClientType">

  </cc1:CascadingDropDown>

  <cc1:CascadingDropDown ID="CascadingDropDown2" runat="server" LoadingText="jiazaizhong" PromptText="qingxuanze"

  ServiceMethod="ClientTypeSubList" ServicePath="/Common/ClientTypeCascadingDropDown.asmx"

  TargetControlID="ddlSubClass" Category="SubClientType" ParentControlID="ddlRootClass">

  </cc1:CascadingDropDown>

  <!--xialaliebiaokongjian-->

  <asp:DropDownList ID="ddlRootClass" runat="server"></asp:DropDownList> 

  <asp:DropDownList ID="ddlSubClass" runat="server"></asp:DropDownList> 

  <!--duiyingdeCascadingDropDownkongjian-->

  <cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" LoadingText="jiazaizhong" PromptText="qingxuanze"

  ServiceMethod="ClientTypeRootList" ServicePath="/Common/ClientTypeCascadingDropDown.asmx"

  TargetControlID="ddlRootClass" Category="RootClientType">

  </cc1:CascadingDropDown>

  <cc1:CascadingDropDown ID="CascadingDropDown2" runat="server" LoadingText="jiazaizhong" PromptText="qingxuanze"

  ServiceMethod="ClientTypeSubList" ServicePath="/Common/ClientTypeCascadingDropDown.asmx"

  TargetControlID="ddlSubClass" Category="SubClientType" ParentControlID="ddlRootClass">

  </cc1:CascadingDropDown>zhuyiCascadingDropDownrkongjianzhongdeCategoryshezhiCategoryzhuyaojiushiweiniCascadingDropDownrkongjianduiyingdexialaliebiaokongjianxuandingdezhiqugemingzihaoqufenshixialaliebiaodezhisuoyizhegedequdebuyiyangServiceMethodzhuyaojiushiduiyingWebSerivcedefangfalezhimingdangqianCascadingDropDownkongjian使shiyongnageWebSerivcezhongdefangfaqitademejiubuxishuole

  zailaikanWebServicededaimaview plaincopy to clipboardprint?

  /// <summary>

  /// ClientType Ajaxxialaliebiaoshujufuwuzhuyidaimazhongdeshiquanjiao使shiyongdeshihoutihuanchengbanjiaode

  /// </summary>

  WebService(Namespace = "http:tempuri.org/")

  WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)

  System.Web.Script.Services.ScriptService //<-zheduanbixudecunzai

  public class ClientTypeCascadingDropDown : System.Web.Services.WebService

  {

  

  WebMethod

  //yijikehuleibiexiangguandeWebServicefangfa

  public CascadingDropDownNameValue ClientTypeRootList(string knownCategoryValues,string category) //<-chuleClientTypeRootListzhegefangfamingkebiandongqitabunengbiandong

  {

  StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); //<-zheduanyedeyouhehe

  

  //zhelijiukeyifangnideshujukuxiangguandaimabirubayijikehuleibiecongshujukuquchulairanhoucunfangzaiyigeshuzuzhong

  //yinweizhelishiyijikehudexialaliebiaosuoyibuyongquguannagecategorydezhi

  //Model.ClientTypeshiwojiandeyigeshitileiqizhongyouClientTypeName,ClientTypeID,ParentClientTypeIDjigeshuxing

  //Model.ClientType model = new Model.ClientType();

  //Model.ClientType models = new Model.ClientType;

  //dangranniyekeyi使shiyongDataSetDataTabeldengzaiforeachnabianbaliebiaoxuyaodezhitianchongjinqujiuhao

  

  //xiayibufenshixialaliebiaotianchongdaima

  List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();

  

  foreach (Model.ClientType model in models)

  {

  values.Add(new CascadingDropDownNameValue(model.ClientTypeName,model.ClientTypeID.ToString()));

  }

  

  return values.ToArray();

  }

  

  WebMethod

  //erjikehuleibiexiangguandeWebServicefangfa

  public CascadingDropDownNameValue ClientTypeSubList(string knownCategoryValues, string category) //<-chuleClientTypeRootListzhegefangfamingkebiandongqitabunengbiandong

  {

  StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); //<-zheduanyedeyouhehe

  

  //erjikehudexialaliebiaodequdeyijidecategorydezhiyixiadaimashipanduanshangjiliebiaodecategoryzhicunzaihuobushikongdehuabazhifugeiparentClientTypeID

  //RootClientTypeshiyijiCascadingDropDownshezhidecategoryshuxingmingcheng

  int parentClientTypeID;

  if (!kv.ContainsKey("RootClientType") || !Int32.TryParse(kv"RootClientType", out parentClientTypeID))

  {

  return null;

  }

  

  //zhelijiukeyifangnideshujukuxiangguandaimabirubayijikehuleibiecongshujukuquchulairanhoucunfangzaiyigeshuzuzhong

  //Model.ClientTypeshiwojiandeyigeshitileiqizhongyouClientTypeName,ClientTypeID,ParentClientTypeIDjigeshuxing

  //Model.ClientType model = new Model.ClientType();

  //Model.ClientType models = new Model.ClientType;

  //dangranniyekeyi使shiyongDataSetDataTabeldengzaiforeachnabianbaliebiaoxuyaodezhitianchongjinqujiuhao

  

  List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();

  

  foreach (Model.ClientType model in models)

  {

  values.Add(new CascadingDropDownNameValue(model.ClientTypeName, model.ClientTypeID.ToString()));

  }

  

  return values.ToArray();

  }

  

  }

  /// <summary>

  /// ClientType Ajaxxialaliebiaoshujufuwuzhuyidaimazhongdeshiquanjiao使shiyongdeshihoutihuanchengbanjiaode

  /// </summary>

  WebService(Namespace = "http:tempuri.org/")

  WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)

  System.Web.Script.Services.ScriptService //<-zheduanbixudecunzai

  public class ClientTypeCascadingDropDown : System.Web.Services.WebService

  {

  WebMethod

  //yijikehuleibiexiangguandeWebServicefangfa

  public CascadingDropDownNameValue ClientTypeRootList(string knownCategoryValues,string category) //<-chuleClientTypeRootListzhegefangfamingkebiandongqitabunengbiandong

  {

  StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); //<-zheduanyedeyouhehe

  //zhelijiukeyifangnideshujukuxiangguandaimabirubayijikehuleibiecongshujukuquchulairanhoucunfangzaiyigeshuzuzhong

  //yinweizhelishiyijikehudexialaliebiaosuoyibuyongquguannagecategorydezhi

  //Model.ClientTypeshiwojiandeyigeshitileiqizhongyouClientTypeName,ClientTypeID,ParentClientTypeIDjigeshuxing

  //Model.ClientType model = new Model.ClientType();

  //Model.ClientType models = new Model.ClientType;

  //dangranniyekeyi使shiyongDataSetDataTabeldengzaiforeachnabianbaliebiaoxuyaodezhitianchongjinqujiuhao

  //xiayibufenshixialaliebiaotianchongdaima

  List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();

  foreach (Model.ClientType model in models)

  {

  values.Add(new CascadingDropDownNameValue(model.ClientTypeName,model.ClientTypeID.ToString()));

  }

  return values.ToArray();

  }

  WebMethod

  //erjikehuleibiexiangguandeWebServicefangfa

  public CascadingDropDownNameValue ClientTypeSubList(string knownCategoryValues, string category) //<-chuleClientTypeRootListzhegefangfamingkebiandongqitabunengbiandong

  {

  StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); //<-zheduanyedeyouhehe

  //erjikehudexialaliebiaodequdeyijidecategorydezhiyixiadaimashipanduanshangjiliebiaodecategoryzhicunzaihuobushikongdehuabazhifugeiparentClientTypeID

  //RootClientTypeshiyijiCascadingDropDownshezhidecategoryshuxingmingcheng

  int parentClientTypeID;

  if (!kv.ContainsKey("RootClientType") || !Int32.TryParse(kv"RootClientType", out parentClientTypeID))

  {

  return null;

  }

  //zhelijiukeyifangnideshujukuxiangguandaimabirubayijikehuleibiecongshujukuquchulairanhoucunfangzaiyigeshuzuzhong

  //Model.ClientTypeshiwojiandeyigeshitileiqizhongyouClientTypeName,ClientTypeID,ParentClientTypeIDjigeshuxing

  //Model.ClientType model = new Model.ClientType();

  //Model.ClientType models = new Model.ClientType;

  //dangranniyekeyi使shiyongDataSetDataTabeldengzaiforeachnabianbaliebiaoxuyaodezhitianchongjinqujiuhao

  List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();

  foreach (Model.ClientType model in models)

  {

  values.Add(new CascadingDropDownNameValue(model.ClientTypeName, model.ClientTypeID.ToString()));

  }

  return values.ToArray();

  }

  }jibenshangyigeCascadingDropDownkongjianjiuhuiyingduiyigeWebserivcedefangfaruguozaiyoudisangedisigeCascadingDropDownanClientTypeSubListweidisangedisigeCascadingDropDowntianjiaduiyingWebServicefangfa

  chuchuhttp://blog.breakn.net/article.asp?id=389原文
 
 
  基本怎么用这里就不啰嗦了,网上有很多文章介绍,包括asp.net那边也有示例可以下载,这里重点说说Category这个属性及如何构建webservice,CascadingDropDown得和webservice配合使用才行。先看页面控件代码view plaincopy to clipboardprint? <!--下拉列表控件--> <asp:DropDownList ID="ddlRootClass" runat="server"></asp:DropDownList>&nbsp; <asp:DropDownList ID="ddlSubClass" runat="server"></asp:DropDownList>&nbsp; <!--对应的CascadingDropDown控件--> <cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" LoadingText="加载中" PromptText="请选择" ServiceMethod="ClientTypeRootList" ServicePath="/Common/ClientTypeCascadingDropDown.asmx" TargetControlID="ddlRootClass" Category="RootClientType"> </cc1:CascadingDropDown> <cc1:CascadingDropDown ID="CascadingDropDown2" runat="server" LoadingText="加载中" PromptText="请选择" ServiceMethod="ClientTypeSubList" ServicePath="/Common/ClientTypeCascadingDropDown.asmx" TargetControlID="ddlSubClass" Category="SubClientType" ParentControlID="ddlRootClass"> </cc1:CascadingDropDown> <!--下拉列表控件--> <asp:DropDownList ID="ddlRootClass" runat="server"></asp:DropDownList>&nbsp; <asp:DropDownList ID="ddlSubClass" runat="server"></asp:DropDownList>&nbsp; <!--对应的CascadingDropDown控件--> <cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" LoadingText="加载中" PromptText="请选择" ServiceMethod="ClientTypeRootList" ServicePath="/Common/ClientTypeCascadingDropDown.asmx" TargetControlID="ddlRootClass" Category="RootClientType"> </cc1:CascadingDropDown> <cc1:CascadingDropDown ID="CascadingDropDown2" runat="server" LoadingText="加载中" PromptText="请选择" ServiceMethod="ClientTypeSubList" ServicePath="/Common/ClientTypeCascadingDropDown.asmx" TargetControlID="ddlSubClass" Category="SubClientType" ParentControlID="ddlRootClass"> </cc1:CascadingDropDown>  注意CascadingDropDownr控件中的Category设置,Category主要就是为你CascadingDropDownr控件对应的下拉列表控件选定的值取个名字,好区分是下拉列表的值,所以这个得取的不一样。ServiceMethod主要就是对应WebSerivce的方法了,指明当前CascadingDropDown控件使用哪个WebSerivce中的方法,其它的么就不细说了。   再来看WebService的代码view plaincopy to clipboardprint? /// <summary> /// ClientType Ajax下拉列表数据服务(注意代码中的[]是全角,使用的时候替换成半角的) /// </summary> [WebService(Namespace = "http:tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.Web.Script.Services.ScriptService] //<-这段必须得存在 public class ClientTypeCascadingDropDown : System.Web.Services.WebService { [WebMethod] //一级客户类别相关的WebService方法 public CascadingDropDownNameValue[] ClientTypeRootList(string knownCategoryValues,string category) //<-除了ClientTypeRootList这个方法名可变动,其它不能变动 { StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); //<-这段也得有,呵呵 //这里就可以放你的数据库相关代码,比如把一级客户类别从数据库取出来然后存放在一个数组中 //因为这里是一级客户的下拉列表,所以不用去管那个category的值 //Model.ClientType是我建的一个实体类,其中有ClientTypeName,ClientTypeID,ParentClientTypeID几个属性 //Model.ClientType model = new Model.ClientType(); //Model.ClientType[] models = new Model.ClientType[]; //当然你也可以使用DataSet、DataTabel等,在foreach那边把列表需要的值填充进去就好 //下以部分是下拉列表填充代码 List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>(); foreach (Model.ClientType model in models) { values.Add(new CascadingDropDownNameValue(model.ClientTypeName,model.ClientTypeID.ToString())); } return values.ToArray(); } [WebMethod] //二级客户类别相关的WebService方法 public CascadingDropDownNameValue[] ClientTypeSubList(string knownCategoryValues, string category) //<-除了ClientTypeRootList这个方法名可变动,其它不能变动 { StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); //<-这段也得有,呵呵 //二级客户的下拉列表,得取得一级的category的值,以下代码是判断上级列表的category值,存在或不是空的话把值赋给parentClientTypeID //RootClientType是一级CascadingDropDown设置的category属性名称 int parentClientTypeID; if (!kv.ContainsKey("RootClientType") || !Int32.TryParse(kv["RootClientType"], out parentClientTypeID)) { return null; } //这里就可以放你的数据库相关代码,比如把一级客户类别从数据库取出来然后存放在一个数组中 //Model.ClientType是我建的一个实体类,其中有ClientTypeName,ClientTypeID,ParentClientTypeID几个属性 //Model.ClientType model = new Model.ClientType(); //Model.ClientType[] models = new Model.ClientType[]; //当然你也可以使用DataSet、DataTabel等,在foreach那边把列表需要的值填充进去就好 List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>(); foreach (Model.ClientType model in models) { values.Add(new CascadingDropDownNameValue(model.ClientTypeName, model.ClientTypeID.ToString())); } return values.ToArray(); } } /// <summary> /// ClientType Ajax下拉列表数据服务(注意代码中的[]是全角,使用的时候替换成半角的) /// </summary> [WebService(Namespace = "http:tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.Web.Script.Services.ScriptService] //<-这段必须得存在 public class ClientTypeCascadingDropDown : System.Web.Services.WebService { [WebMethod] //一级客户类别相关的WebService方法 public CascadingDropDownNameValue[] ClientTypeRootList(string knownCategoryValues,string category) //<-除了ClientTypeRootList这个方法名可变动,其它不能变动 { StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); //<-这段也得有,呵呵 //这里就可以放你的数据库相关代码,比如把一级客户类别从数据库取出来然后存放在一个数组中 //因为这里是一级客户的下拉列表,所以不用去管那个category的值 //Model.ClientType是我建的一个实体类,其中有ClientTypeName,ClientTypeID,ParentClientTypeID几个属性 //Model.ClientType model = new Model.ClientType(); //Model.ClientType[] models = new Model.ClientType[]; //当然你也可以使用DataSet、DataTabel等,在foreach那边把列表需要的值填充进去就好 //下以部分是下拉列表填充代码 List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>(); foreach (Model.ClientType model in models) { values.Add(new CascadingDropDownNameValue(model.ClientTypeName,model.ClientTypeID.ToString())); } return values.ToArray(); } [WebMethod] //二级客户类别相关的WebService方法 public CascadingDropDownNameValue[] ClientTypeSubList(string knownCategoryValues, string category) //<-除了ClientTypeRootList这个方法名可变动,其它不能变动 { StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); //<-这段也得有,呵呵 //二级客户的下拉列表,得取得一级的category的值,以下代码是判断上级列表的category值,存在或不是空的话把值赋给parentClientTypeID //RootClientType是一级CascadingDropDown设置的category属性名称 int parentClientTypeID; if (!kv.ContainsKey("RootClientType") || !Int32.TryParse(kv["RootClientType"], out parentClientTypeID)) { return null; } //这里就可以放你的数据库相关代码,比如把一级客户类别从数据库取出来然后存放在一个数组中 //Model.ClientType是我建的一个实体类,其中有ClientTypeName,ClientTypeID,ParentClientTypeID几个属性 //Model.ClientType model = new Model.ClientType(); //Model.ClientType[] models = new Model.ClientType[]; //当然你也可以使用DataSet、DataTabel等,在foreach那边把列表需要的值填充进去就好 List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>(); foreach (Model.ClientType model in models) { values.Add(new CascadingDropDownNameValue(model.ClientTypeName, model.ClientTypeID.ToString())); } return values.ToArray(); } }  基本上一个CascadingDropDown控件就会应对一个Webserivce的方法,如果再有第三个,第四个CascadingDropDown,按ClientTypeSubList为第三个,第四个CascadingDropDown添加对应WebService方法 出处:[url=http://blog.breakn.net/article.asp?id=389]http://blog.breakn.net/article.asp?id=389[/url]
󰈣󰈤
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

网络安全治理:国家安全保障的主要方向是打击犯罪,而不是处置和惩罚受害者

来源:中国青年报 新的攻击方法不断涌现,黑客几乎永远占据网络攻击的上风,我们不可能通过技术手段杜绝网络攻击。国家安全保障的主要方向是打击犯罪,而不是处置和惩罚...

 
 
 
>>返回首页<<
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 
 热帖排行
 
黑色魅力_醉人的美
梦幻蒙眬_如痴如醉
北京的“尖叫”建筑
高天上流云
 
 
王朝网络微信公众号
微信扫码关注本站公众号wangchaonetcn
 
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
©2005- 王朝网络 版权所有