惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy International News Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Troy Hunt's Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Attack and Defense Labs
Attack and Defense Labs
S
Secure Thoughts
V2EX - 技术
V2EX - 技术
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
O
OpenAI News
Cloudbric
Cloudbric
Google Online Security Blog
Google Online Security Blog
Schneier on Security
Schneier on Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Help Net Security
Help Net Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
L
Lohrmann on Cybersecurity
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Spread Privacy
Spread Privacy
NISL@THU
NISL@THU
N
News and Events Feed by Topic
T
Tenable Blog
S
Security @ Cisco Blogs
N
News and Events Feed by Topic
The Hacker News
The Hacker News
C
CXSECURITY Database RSS Feed - CXSecurity.com
宝玉的分享
宝玉的分享
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
V
Visual Studio Blog
P
Proofpoint News Feed
Webroot Blog
Webroot Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 三生石上(FineUI控件)
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Jina AI
Jina AI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
腾讯CDC
L
LangChain Blog
The Register - Security
The Register - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东

博客园 - nikytwo

Install Tomcat 7 on CentOS, RHEL, or Fedora [转]如何安全的存储密码 打败 IE 的葵花宝典:CSS Bug Table 域名的DNS解析指南 IE6实现PNG图片透明 JQuery EasyUI 之 combobox plugin JQuery EasyUI 之 validatebox plugin JQuery easyUI 之 datebox plugin Asp.NET + OWC 输出Chart(图表) Route命令使用详解 最近写 ASP.NET 中出现的错误 & 实现DataTable和DataSet类型的客户端/服务器端自动转换 Apache + PHP 安装日志 CSS图片垂直居中 - nikytwo - 博客园 CSS 条件缩放图片 SQL:行合并问题 & 使用 SP_executesql 从exec('SQL语句') 中得到一个返回值 Dataset.Readxml(stream) 错误 “缺少根元素” 分页 web Service 传输 Dataset (大数据量) Delphi 调用 Webservice (ASP.NET)
CascadingDropDown
nikytwo · 2009-05-20 · via 博客园 - nikytwo

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

官方: CascadingDropDown DemonstrationUsing CascadingDropDown with a Database

http://www.ajaxasp.net.cn/Demos/CascadingDropDown/CascadingDropDown.aspx

斜体 属性为可选属性:

<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" />

  • TargetControlID - 扩展的 DropDownList 控件 ID
  • Category - 对应的数据的分类,例如上面例子中的“区域”、“省份”或者“城市”
  • PromptText - 在 DropDownList 被选择前提示用户的信息
  • PromptValue - 对应提示信息的 Value,这里指的是 DropDownList 中一个 ListItem 中的 Value 值
  • EmptyText - 当从 Web Service 中获得数据为空的时候 DropDownList 显示的信息,可选
  • EmptyValue - 对应当数据项为空的时候 DropDownList 中显示 EmptyText 的信息的 Value,这里指的是 DropDownList 中一个 ListItem 中的 Value 值,可选
  • LoadingText - 当 CascadingDropDown 在和 Web Service 进行数据通信的时候显示的信息
  • ServicePath - 对应的获得数据的 Web Service 路径,如果对应的 Web Service 方法为当前页的 Web Service 方法时,需要将其指定为空
  • ServiceMethod - 对应的获得 Web Service 方法名,它需要指定为如下的函数签名
    [System.Web.Services.WebMethod]

    [System.Web.Script.Services.ScriptMethod]

    public CascadingDropDownNameValue[] GetDropDownContents(

    string knownCategoryValues, string category) { ... }

    注意:
    你可以替换上面示例中的方法名称,GetDropDownContents 为任何你想要的方法名,但是返回值和参数列表需要保持完全一致。
  • ContextKey - 一个可用于传入 Web Service 方法的参数,该参数将用于 Web Service 根据客户端的不同操作产生相应的不同的返回结果,当采用 ContextKey 的时候,这个方法的函数签名如下表示:
    [System.Web.Services.WebMethod]

    [System.Web.Script.Services.ScriptMethod]

    public CascadingDropDownNameValue[] GetDropDownContents(

    string knownCategoryValues,

    string category, string contextKey) { ... }

    注意:
    你可以替换上面示例中的方法名称,GetDropDownContents 为任何你想要的方法名,但是返回值和参数列表需要保持完全一致。
  • UseContextKey - 指定是否采用 ContextKey,当函数签名采用了带有 ContextKey 的函数签名时,这个属性将被自动设置为 True
  • ParentControlID - 上一级 DropDownList 控件的 ID,当其没有上一级 DropDownList 的时候,该属性被设置为空,例如上面例子中的 “区域”
  • SelectedValue - 默认的初始化选中值的 Value,这里指的是 DropDownList 中 ListItem 的 Value 值

自己写的代码:

服务端代码:


        [WebMethod]
        [System.Web.Script.Services.ScriptMethod()]
        
public static AjaxControlToolkit.CascadingDropDownNameValue[] GetParentService(string knownCategoryValues, string category)
        
{
            System.Data.DataSet ds 
= Agr.AgrOperate.GetServiceItemsBy(0);
            
if (ds.Tables[0].Rows.Count > 0)
            
{
                System.Collections.Generic.List
<AjaxControlToolkit.CascadingDropDownNameValue> Values
                    
= new System.Collections.Generic.List<AjaxControlToolkit.CascadingDropDownNameValue>();
                Values.Add(
new AjaxControlToolkit.CascadingDropDownNameValue("""-1"));
                
foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
                
{
                    Values.Add(
new AjaxControlToolkit.CascadingDropDownNameValue(dr["ItemsName"].ToString(), dr["PID"].ToString()));
                }

                Values.Add(
new AjaxControlToolkit.CascadingDropDownNameValue("其它""99"));

                
return Values.ToArray();
            }

            
else
            
{
                
return null;
            }

        }


        
//加载子受理项目
        [WebMethod]
        [System.Web.Script.Services.ScriptMethod()]
        
public static AjaxControlToolkit.CascadingDropDownNameValue[] GetSubService(string knownCategoryValues, string category)
        
{
            System.Collections.Specialized.StringDictionary kv
                
= AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
            
int PID;
            
//"ParentID"是上一级CascadingDropDown设置的category属性名称 
            if (!kv.ContainsKey("ParentID"|| !Int32.TryParse(kv["ParentID"], out PID))
            
{
                
return null;
            }


            System.Data.DataSet ds 
= Agr.AgrOperate.GetServiceItemsBy(PID);
            
if (ds.Tables[0].Rows.Count > 0)
            
{
                System.Collections.Generic.List
<AjaxControlToolkit.CascadingDropDownNameValue> Values
                    
= new System.Collections.Generic.List<AjaxControlToolkit.CascadingDropDownNameValue>();
                Values.Add(
new AjaxControlToolkit.CascadingDropDownNameValue("""-1"));
                
foreach (System.Data.DataRow dr in ds.Tables[0].Rows)
                
{
                    Values.Add(
new AjaxControlToolkit.CascadingDropDownNameValue(dr["ItemsName"].ToString(), dr["PID"].ToString()));
                }


                
return Values.ToArray();
            }

            
else
            
{
                
return null;
            }

        }

 HTML页面代码:


                
<td align="right">
                    协议受理项目
                
</td>
                
<td align="left">
                    
<asp:DropDownList ID="drplstParentService" runat="server" BackColor="#FFFFC0" CssClass="cssInputBox"
                        ToolTip
="请选择要查询的受理项目" Width="100%">
                    
</asp:DropDownList>
                    
<cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="drplstParentService"
                     Category
="ParentID" LoadingText="加载中" PromptText="" ServiceMethod="GetParentService">
                    
</cc1:CascadingDropDown>
                
</td>
                
<td align="right">
                    子受理项目
                
</td>
                
<td align="left">
                    
<asp:DropDownList ID="drplstSubService" runat="server" BackColor="#FFFFC0" CssClass="cssInputBox"
                        ToolTip
="请选择要查询的子受理项目" Width="100%">
                    
</asp:DropDownList>
                    
<cc1:CascadingDropDown ID="CascadingDropDown2" runat="server" TargetControlID="drplstSubService" 
                    Category
="SubID" LoadingText="加载中" PromptText="" ServiceMethod="GetSubService" ParentControlID="drplstParentService">
                    
</cc1:CascadingDropDown>
                
</td>

 另:使用 CascadingDropDown 要设置 EnableEventValidation="false" ,哪位高人知道有其他做法吗?