| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> asp >> asp.net AJAX中的CascadingDropDown控件使用心得 asp.net AJAX zhong de CascadingDropDown kong jian shi yong xin de
 

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动态加载控件的"追赶论"》
下一篇《用isapi rewrite实现asp的HTML静态化》
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

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

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

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

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
  基本怎么用这里就不啰嗦了,网上有很多文章介绍,包括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]
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
赏心悦目的模特儿(9)
赏心悦目的模特儿(8)
赏心悦目的模特儿(7)
赏心悦目的模特儿(6)
周六一日游--绿野翠蜂场(一)
骆驼峰
下一站上环
杂乱的几张Danang
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
©2005- 王朝网络 版权所有