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

推荐订阅源

V
Vulnerabilities – Threatpost
U
Unit 42
F
Fortinet All Blogs
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
F
Full Disclosure
月光博客
月光博客
Engineering at Meta
Engineering at Meta
博客园_首页
The Register - Security
The Register - Security
G
Google Developers Blog
The Cloudflare Blog
博客园 - Franky
K
Kaspersky official blog
A
Arctic Wolf
Scott Helme
Scott Helme
C
Cisco Blogs
Hugging Face - Blog
Hugging Face - Blog
C
Check Point Blog
NISL@THU
NISL@THU
AI
AI
D
DataBreaches.Net
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Stack Overflow Blog
Stack Overflow Blog
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
Vercel News
Vercel News
T
Tor Project blog
P
Privacy International News Feed
D
Docker
I
Intezer
L
LangChain Blog
P
Proofpoint News Feed
Security Latest
Security Latest
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
博客园 - 聂微东
AWS News Blog
AWS News Blog
Martin Fowler
Martin Fowler
P
Privacy & Cybersecurity Law Blog
V
V2EX
Last Week in AI
Last Week in AI
C
Cybersecurity and Infrastructure Security Agency CISA
The Hacker News
The Hacker News
T
Tenable Blog
Blog — PlanetScale
Blog — PlanetScale
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog

博客园 - 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" ,哪位高人知道有其他做法吗?