功能:
用来附加到一个ASP.NET DropDownList控件之上,以便自动产生一整组DropDownList控件中的选项,以供用户选择。
属性:
    
        
实例代码:
aspx页面:
    
 <html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head id="Head1" runat="server">
<head id="Head1" runat="server">
 <title>示范如何使用“级联下拉菜单”(CascadingDropDown)</title>
    <title>示范如何使用“级联下拉菜单”(CascadingDropDown)</title>
 <link href="style.css" type="text/css" rel="Stylesheet" />
    <link href="style.css" type="text/css" rel="Stylesheet" />
 </head>
</head>
 <body onload="focus();">
<body onload="focus();">
 <div class="banner">
    <div class="banner">
 <a href="http://abcdwxc.cnblogs.com/" target="_blank">
        <a href="http://abcdwxc.cnblogs.com/" target="_blank">
 级联下拉菜单的使用(CascadingDropDown控件)------王晓成博客
            级联下拉菜单的使用(CascadingDropDown控件)------王晓成博客
 </a>
        </a>
 </div>
    </div>
 <div class="description">
    <div class="description">
 <ul>
        <ul>
 <li>从第一个下拉列表框选择某一个<strong>“县市”</strong>之后,用来选择<strong>“乡镇区市”</strong>的下拉列表框就可以进行选取。 </li>
            <li>从第一个下拉列表框选择某一个<strong>“县市”</strong>之后,用来选择<strong>“乡镇区市”</strong>的下拉列表框就可以进行选取。 </li>
 <li>从第二个下拉列表框选择某一个<strong>“乡镇区市”</strong>之后,便可以查看该乡镇区市的邮政编码。 </li>
            <li>从第二个下拉列表框选择某一个<strong>“乡镇区市”</strong>之后,便可以查看该乡镇区市的邮政编码。 </li>
 </ul>
        </ul>
 </div>
    </div>
 <form id="form1" runat="server">
    <form id="form1" runat="server">
 <asp:ScriptManager ID="ScriptManager1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
 </asp:ScriptManager>
        </asp:ScriptManager>
 <center>
        <center>
 <table border="1" width="480px">
        <table border="1" width="480px">
 <tr>
            <tr>
 <td style="width: 340px; height: 29px; text-align: right;">
                <td style="width: 340px; height: 29px; text-align: right;">
 请选择县市:</td>
                    请选择县市:</td>
 <td style="width: 140px; height: 29px;">
                <td style="width: 140px; height: 29px;">
 <asp:DropDownList ID="ddlCityName" runat="server">
                    <asp:DropDownList ID="ddlCityName" runat="server">
 </asp:DropDownList></td>
                    </asp:DropDownList></td>
 </tr>
            </tr>
 <tr>
            <tr>
 <td style="width: 340px; text-align: right;">
                <td style="width: 340px; text-align: right;">
 请选择乡镇区市:</td>
                    请选择乡镇区市:</td>
 <td style="width: 140px">
                <td style="width: 140px">
 <asp:DropDownList ID="ddlSubAreaName" runat="server" AutoPostBack="True"
                    <asp:DropDownList ID="ddlSubAreaName" runat="server" AutoPostBack="True" 
 onselectedindexchanged="ddlSubAreaName_SelectedIndexChanged">
                        onselectedindexchanged="ddlSubAreaName_SelectedIndexChanged">
 </asp:DropDownList></td>
                    </asp:DropDownList></td>
 </tr>
            </tr>
 <tr>
            <tr>
 <td style="width: 340px; text-align: right;">
                <td style="width: 340px; text-align: right;">
 邮政编码:</td>
                    邮政编码:</td>
 <td style="width: 140px">
                <td style="width: 140px">
 <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
 <ContentTemplate>
                        <ContentTemplate>
 <asp:TextBox ID="TextBoxZipCode" runat="server"></asp:TextBox>
                            <asp:TextBox ID="TextBoxZipCode" runat="server"></asp:TextBox>
 </ContentTemplate>
                        </ContentTemplate>
 <Triggers>
                        <Triggers>
 <asp:AsyncPostBackTrigger ControlID="ddlSubAreaName" EventName="SelectedIndexChanged" />
                            <asp:AsyncPostBackTrigger ControlID="ddlSubAreaName" EventName="SelectedIndexChanged" />
 </Triggers>
                        </Triggers>
 </asp:UpdatePanel>
                    </asp:UpdatePanel>
 </td>
                </td>
 </tr>
            </tr>
 </table>
        </table>
 </center>
        </center>
 <br />
        <br />        
 <ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server" Category="City"
        <ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server" Category="City"
 LoadingText="读取县市数据中
            LoadingText="读取县市数据中 " PromptText="请选择县市名称" ServiceMethod="GetCityNames" ServicePath="ZipCodeWebService.asmx"
" PromptText="请选择县市名称" ServiceMethod="GetCityNames" ServicePath="ZipCodeWebService.asmx"
 TargetControlID="ddlCityName">
            TargetControlID="ddlCityName">
 </ajaxToolkit:CascadingDropDown>
        </ajaxToolkit:CascadingDropDown>
 <ajaxToolkit:CascadingDropDown ID="CascadingDropDown2" runat="server" Category="SubArea"
        <ajaxToolkit:CascadingDropDown ID="CascadingDropDown2" runat="server" Category="SubArea"
 LoadingText="读取乡镇区市数据中
            LoadingText="读取乡镇区市数据中 " ParentControlID="ddlCityName" PromptText="请选择乡镇区市"
" ParentControlID="ddlCityName" PromptText="请选择乡镇区市"
 ServiceMethod="GetSubAreaByCityID" ServicePath="ZipCodeWebService.asmx" TargetControlID="ddlSubAreaName">
            ServiceMethod="GetSubAreaByCityID" ServicePath="ZipCodeWebService.asmx" TargetControlID="ddlSubAreaName">
 </ajaxToolkit:CascadingDropDown>
        </ajaxToolkit:CascadingDropDown>
 </form>
    </form>
 </body>
</body>
 </html>
</html>

 CS页面:
CS页面: 
 protected void ddlSubAreaName_SelectedIndexChanged(object sender, EventArgs e)
   protected void ddlSubAreaName_SelectedIndexChanged(object sender, EventArgs e)
 {
    {
 //将邮政编码显示在文字方块中。
        //将邮政编码显示在文字方块中。
 this.TextBoxZipCode.Text = this.ddlSubAreaName.SelectedItem.Value;
        this.TextBoxZipCode.Text = this.ddlSubAreaName.SelectedItem.Value;
 }
    }
 编写相应的WebServices:
编写相应的WebServices:
 using System;
using System;
 using System.Linq;
using System.Linq;
 using System.Web;
using System.Web;
 using System.Collections;
using System.Collections;
 using System.Collections.Generic;
using System.Collections.Generic;
 using System.Web.Services;
using System.Web.Services;
 using System.Web.Services.Protocols;
using System.Web.Services.Protocols;
 using System.Xml.Linq;
using System.Xml.Linq;
 using System.Data.SqlClient;
using System.Data.SqlClient;
 using System.Web.Script.Services;
using System.Web.Script.Services;
 using AjaxControlToolkit;
using AjaxControlToolkit;
 using System.Data;
using System.Data;
 using System.Web.Configuration;
using System.Web.Configuration;
 using System.Configuration;
using System.Configuration;
 using System.Collections.Specialized;
using System.Collections.Specialized;

 /// <summary>
/// <summary>
 /// Summary description for ZipCodeWebService
/// Summary description for ZipCodeWebService
 /// </summary>
/// </summary>
 [WebService(Namespace = "http://tempuri.org/")]
[WebService(Namespace = "http://tempuri.org/")]
 [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
 // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
 [System.Web.Script.Services.ScriptService]
 [System.Web.Script.Services.ScriptService]

 public class ZipCodeWebService : System.Web.Services.WebService {
public class ZipCodeWebService : System.Web.Services.WebService {

 public ZipCodeWebService () {
    public ZipCodeWebService () {

 //Uncomment the following line if using designed components
        //Uncomment the following line if using designed components 
 //InitializeComponent();
        //InitializeComponent(); 
 }
    }

 [WebMethod]
    [WebMethod]
 public CascadingDropDownNameValue[] GetCityNames(string knownCategoryValues, string category)
    public CascadingDropDownNameValue[] GetCityNames(string knownCategoryValues, string category)
 {
    {
 //声明 CascadingDropDownNameValue 数组。
         //声明 CascadingDropDownNameValue 数组。        
 List<CascadingDropDownNameValue> values =new List<CascadingDropDownNameValue>();
        List<CascadingDropDownNameValue> values =new List<CascadingDropDownNameValue>();
 //Dim values As New Generic.List(Of CascadingDropDownNameValue)
        //Dim values As New Generic.List(Of CascadingDropDownNameValue)

 // 取得 web.config 中的数据库联机字符串设定来建立 SQL 联机对象。
        // 取得 web.config 中的数据库联机字符串设定来建立 SQL 联机对象。
 string connectionString = ConfigurationManager.ConnectionStrings["County"].ConnectionString;
        string connectionString = ConfigurationManager.ConnectionStrings["County"].ConnectionString;
 SqlConnection connection = new SqlConnection(connectionString);
        SqlConnection connection = new SqlConnection(connectionString);        
 SqlCommand command = new SqlCommand("SELECT CName, CID FROM County");
        SqlCommand command = new SqlCommand("SELECT CName, CID FROM County");
 command.Connection = connection;
        command.Connection = connection;
 // 开启数据库连接并将数据读入数据读取器中。
        // 开启数据库连接并将数据读入数据读取器中。
 connection.Open();
        connection.Open();
 SqlDataReader sdr = command.ExecuteReader();
        SqlDataReader sdr = command.ExecuteReader();
 while (sdr.Read())
        while (sdr.Read())
 {
        {
 // 将「县市名称」与「县市代号」新增到数组中。
           // 将「县市名称」与「县市代号」新增到数组中。
 values.Add(new CascadingDropDownNameValue(sdr.GetSqlChars(0).Value.ToString(),sdr.GetInt32(1).ToString()));
            values.Add(new CascadingDropDownNameValue(sdr.GetSqlChars(0).Value.ToString(),sdr.GetInt32(1).ToString()));
 }
        }
 return values.ToArray();
        return values.ToArray();        
 }
    }

 public CascadingDropDownNameValue[] GetSubAreaByCityID(string knownCategoryValues, string category)
    public CascadingDropDownNameValue[] GetSubAreaByCityID(string knownCategoryValues, string category)
 {
    {
 StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
 int cityID;
        int cityID;

 if (!kv.ContainsKey("cityID") || !Int32.TryParse(kv["cityID"], out cityID))
        if (!kv.ContainsKey("cityID") || !Int32.TryParse(kv["cityID"], out cityID))
 {
        {
 return null;
            return null;
 }
        }
 // 声明 CascadingDropDownNameValue 数组。
       // 声明 CascadingDropDownNameValue 数组。
 List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
        List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
 // 取得 web.config 中的数据库联机字符串设定来建立 SQL 联机对象。
        // 取得 web.config 中的数据库联机字符串设定来建立 SQL 联机对象。
 string connectionString = ConfigurationManager.ConnectionStrings["County"].ConnectionString;
        string connectionString = ConfigurationManager.ConnectionStrings["County"].ConnectionString;
 SqlConnection connection = new SqlConnection(connectionString);
        SqlConnection connection = new SqlConnection(connectionString);
 SqlCommand command = new SqlCommand(@"ELECT VName, VCode FROM Village WHERE CountyID =" + cityID);
        SqlCommand command = new SqlCommand(@"ELECT VName, VCode FROM Village WHERE CountyID =" + cityID);
 // 开启数据库连接并将数据读入数据读取器中。
        // 开启数据库连接并将数据读入数据读取器中。
 connection.Open();
        connection.Open();
 SqlDataReader sdr = command.ExecuteReader();
        SqlDataReader sdr = command.ExecuteReader();
 while (sdr.Read())
        while (sdr.Read())
 {
        {
 // 将「乡镇区市名称」与「邮政编码」新增到数组中。
         // 将「乡镇区市名称」与「邮政编码」新增到数组中。
 values.Add(new CascadingDropDownNameValue(sdr.GetSqlString(0).ToString(), sdr.GetSqlString(1).ToString()));
            values.Add(new CascadingDropDownNameValue(sdr.GetSqlString(0).ToString(), sdr.GetSqlString(1).ToString()));
 }
        }
 return values.ToArray();
        return values.ToArray();        
 }
    }
 }
}

 
运行结果:
    

 
用来附加到一个ASP.NET DropDownList控件之上,以便自动产生一整组DropDownList控件中的选项,以供用户选择。
属性:
| TargetControlID | 指定要扩展的DropDownList的ID | 
| Category | DropDownList表示的类别名称,在WebMethod中会用到 | 
| PromptText | 没有选择时显示的文字 | 
| LoadingText | 加载数据时显示的文字 | 
| ServicePath | 获取数据的Web Service,为每个DropDownList都要指定 | 
| ServiceMethod | 获取数据的Web Method | 
| ParentControlID | 要扩展的DropDownList的父控件ID | 
| SelectedValue | 默认的选择项的值 | 
实例代码:
aspx页面:
 <html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server">
<head id="Head1" runat="server"> <title>示范如何使用“级联下拉菜单”(CascadingDropDown)</title>
    <title>示范如何使用“级联下拉菜单”(CascadingDropDown)</title> <link href="style.css" type="text/css" rel="Stylesheet" />
    <link href="style.css" type="text/css" rel="Stylesheet" /> </head>
</head> <body onload="focus();">
<body onload="focus();"> <div class="banner">
    <div class="banner"> <a href="http://abcdwxc.cnblogs.com/" target="_blank">
        <a href="http://abcdwxc.cnblogs.com/" target="_blank"> 级联下拉菜单的使用(CascadingDropDown控件)------王晓成博客
            级联下拉菜单的使用(CascadingDropDown控件)------王晓成博客 </a>
        </a> </div>
    </div> <div class="description">
    <div class="description"> <ul>
        <ul> <li>从第一个下拉列表框选择某一个<strong>“县市”</strong>之后,用来选择<strong>“乡镇区市”</strong>的下拉列表框就可以进行选取。 </li>
            <li>从第一个下拉列表框选择某一个<strong>“县市”</strong>之后,用来选择<strong>“乡镇区市”</strong>的下拉列表框就可以进行选取。 </li> <li>从第二个下拉列表框选择某一个<strong>“乡镇区市”</strong>之后,便可以查看该乡镇区市的邮政编码。 </li>
            <li>从第二个下拉列表框选择某一个<strong>“乡镇区市”</strong>之后,便可以查看该乡镇区市的邮政编码。 </li> </ul>
        </ul> </div>
    </div> <form id="form1" runat="server">
    <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>
        </asp:ScriptManager> <center>
        <center> <table border="1" width="480px">
        <table border="1" width="480px"> <tr>
            <tr> <td style="width: 340px; height: 29px; text-align: right;">
                <td style="width: 340px; height: 29px; text-align: right;"> 请选择县市:</td>
                    请选择县市:</td> <td style="width: 140px; height: 29px;">
                <td style="width: 140px; height: 29px;"> <asp:DropDownList ID="ddlCityName" runat="server">
                    <asp:DropDownList ID="ddlCityName" runat="server"> </asp:DropDownList></td>
                    </asp:DropDownList></td> </tr>
            </tr> <tr>
            <tr> <td style="width: 340px; text-align: right;">
                <td style="width: 340px; text-align: right;"> 请选择乡镇区市:</td>
                    请选择乡镇区市:</td> <td style="width: 140px">
                <td style="width: 140px"> <asp:DropDownList ID="ddlSubAreaName" runat="server" AutoPostBack="True"
                    <asp:DropDownList ID="ddlSubAreaName" runat="server" AutoPostBack="True"  onselectedindexchanged="ddlSubAreaName_SelectedIndexChanged">
                        onselectedindexchanged="ddlSubAreaName_SelectedIndexChanged"> </asp:DropDownList></td>
                    </asp:DropDownList></td> </tr>
            </tr> <tr>
            <tr> <td style="width: 340px; text-align: right;">
                <td style="width: 340px; text-align: right;"> 邮政编码:</td>
                    邮政编码:</td> <td style="width: 140px">
                <td style="width: 140px"> <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate>
                        <ContentTemplate> <asp:TextBox ID="TextBoxZipCode" runat="server"></asp:TextBox>
                            <asp:TextBox ID="TextBoxZipCode" runat="server"></asp:TextBox> </ContentTemplate>
                        </ContentTemplate> <Triggers>
                        <Triggers> <asp:AsyncPostBackTrigger ControlID="ddlSubAreaName" EventName="SelectedIndexChanged" />
                            <asp:AsyncPostBackTrigger ControlID="ddlSubAreaName" EventName="SelectedIndexChanged" /> </Triggers>
                        </Triggers> </asp:UpdatePanel>
                    </asp:UpdatePanel> </td>
                </td> </tr>
            </tr> </table>
        </table> </center>
        </center> <br />
        <br />         <ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server" Category="City"
        <ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server" Category="City" LoadingText="读取县市数据中
            LoadingText="读取县市数据中 " PromptText="请选择县市名称" ServiceMethod="GetCityNames" ServicePath="ZipCodeWebService.asmx"
" PromptText="请选择县市名称" ServiceMethod="GetCityNames" ServicePath="ZipCodeWebService.asmx" TargetControlID="ddlCityName">
            TargetControlID="ddlCityName"> </ajaxToolkit:CascadingDropDown>
        </ajaxToolkit:CascadingDropDown> <ajaxToolkit:CascadingDropDown ID="CascadingDropDown2" runat="server" Category="SubArea"
        <ajaxToolkit:CascadingDropDown ID="CascadingDropDown2" runat="server" Category="SubArea" LoadingText="读取乡镇区市数据中
            LoadingText="读取乡镇区市数据中 " ParentControlID="ddlCityName" PromptText="请选择乡镇区市"
" ParentControlID="ddlCityName" PromptText="请选择乡镇区市" ServiceMethod="GetSubAreaByCityID" ServicePath="ZipCodeWebService.asmx" TargetControlID="ddlSubAreaName">
            ServiceMethod="GetSubAreaByCityID" ServicePath="ZipCodeWebService.asmx" TargetControlID="ddlSubAreaName"> </ajaxToolkit:CascadingDropDown>
        </ajaxToolkit:CascadingDropDown> </form>
    </form> </body>
</body> </html>
</html>

 protected void ddlSubAreaName_SelectedIndexChanged(object sender, EventArgs e)
   protected void ddlSubAreaName_SelectedIndexChanged(object sender, EventArgs e) {
    { //将邮政编码显示在文字方块中。
        //将邮政编码显示在文字方块中。 this.TextBoxZipCode.Text = this.ddlSubAreaName.SelectedItem.Value;
        this.TextBoxZipCode.Text = this.ddlSubAreaName.SelectedItem.Value; }
    }
 using System;
using System; using System.Linq;
using System.Linq; using System.Web;
using System.Web; using System.Collections;
using System.Collections; using System.Collections.Generic;
using System.Collections.Generic; using System.Web.Services;
using System.Web.Services; using System.Web.Services.Protocols;
using System.Web.Services.Protocols; using System.Xml.Linq;
using System.Xml.Linq; using System.Data.SqlClient;
using System.Data.SqlClient; using System.Web.Script.Services;
using System.Web.Script.Services; using AjaxControlToolkit;
using AjaxControlToolkit; using System.Data;
using System.Data; using System.Web.Configuration;
using System.Web.Configuration; using System.Configuration;
using System.Configuration; using System.Collections.Specialized;
using System.Collections.Specialized;
 /// <summary>
/// <summary> /// Summary description for ZipCodeWebService
/// Summary description for ZipCodeWebService /// </summary>
/// </summary> [WebService(Namespace = "http://tempuri.org/")]
[WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.  [System.Web.Script.Services.ScriptService]
 [System.Web.Script.Services.ScriptService]
 public class ZipCodeWebService : System.Web.Services.WebService {
public class ZipCodeWebService : System.Web.Services.WebService {
 public ZipCodeWebService () {
    public ZipCodeWebService () {
 //Uncomment the following line if using designed components
        //Uncomment the following line if using designed components  //InitializeComponent();
        //InitializeComponent();  }
    }
 [WebMethod]
    [WebMethod] public CascadingDropDownNameValue[] GetCityNames(string knownCategoryValues, string category)
    public CascadingDropDownNameValue[] GetCityNames(string knownCategoryValues, string category) {
    { //声明 CascadingDropDownNameValue 数组。
         //声明 CascadingDropDownNameValue 数组。         List<CascadingDropDownNameValue> values =new List<CascadingDropDownNameValue>();
        List<CascadingDropDownNameValue> values =new List<CascadingDropDownNameValue>(); //Dim values As New Generic.List(Of CascadingDropDownNameValue)
        //Dim values As New Generic.List(Of CascadingDropDownNameValue)
 // 取得 web.config 中的数据库联机字符串设定来建立 SQL 联机对象。
        // 取得 web.config 中的数据库联机字符串设定来建立 SQL 联机对象。 string connectionString = ConfigurationManager.ConnectionStrings["County"].ConnectionString;
        string connectionString = ConfigurationManager.ConnectionStrings["County"].ConnectionString; SqlConnection connection = new SqlConnection(connectionString);
        SqlConnection connection = new SqlConnection(connectionString);         SqlCommand command = new SqlCommand("SELECT CName, CID FROM County");
        SqlCommand command = new SqlCommand("SELECT CName, CID FROM County"); command.Connection = connection;
        command.Connection = connection; // 开启数据库连接并将数据读入数据读取器中。
        // 开启数据库连接并将数据读入数据读取器中。 connection.Open();
        connection.Open(); SqlDataReader sdr = command.ExecuteReader();
        SqlDataReader sdr = command.ExecuteReader(); while (sdr.Read())
        while (sdr.Read()) {
        { // 将「县市名称」与「县市代号」新增到数组中。
           // 将「县市名称」与「县市代号」新增到数组中。 values.Add(new CascadingDropDownNameValue(sdr.GetSqlChars(0).Value.ToString(),sdr.GetInt32(1).ToString()));
            values.Add(new CascadingDropDownNameValue(sdr.GetSqlChars(0).Value.ToString(),sdr.GetInt32(1).ToString())); }
        } return values.ToArray();
        return values.ToArray();         }
    }
 public CascadingDropDownNameValue[] GetSubAreaByCityID(string knownCategoryValues, string category)
    public CascadingDropDownNameValue[] GetSubAreaByCityID(string knownCategoryValues, string category) {
    { StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); int cityID;
        int cityID;
 if (!kv.ContainsKey("cityID") || !Int32.TryParse(kv["cityID"], out cityID))
        if (!kv.ContainsKey("cityID") || !Int32.TryParse(kv["cityID"], out cityID)) {
        { return null;
            return null; }
        } // 声明 CascadingDropDownNameValue 数组。
       // 声明 CascadingDropDownNameValue 数组。 List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
        List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>(); // 取得 web.config 中的数据库联机字符串设定来建立 SQL 联机对象。
        // 取得 web.config 中的数据库联机字符串设定来建立 SQL 联机对象。 string connectionString = ConfigurationManager.ConnectionStrings["County"].ConnectionString;
        string connectionString = ConfigurationManager.ConnectionStrings["County"].ConnectionString; SqlConnection connection = new SqlConnection(connectionString);
        SqlConnection connection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand(@"ELECT VName, VCode FROM Village WHERE CountyID =" + cityID);
        SqlCommand command = new SqlCommand(@"ELECT VName, VCode FROM Village WHERE CountyID =" + cityID); // 开启数据库连接并将数据读入数据读取器中。
        // 开启数据库连接并将数据读入数据读取器中。 connection.Open();
        connection.Open(); SqlDataReader sdr = command.ExecuteReader();
        SqlDataReader sdr = command.ExecuteReader(); while (sdr.Read())
        while (sdr.Read()) {
        { // 将「乡镇区市名称」与「邮政编码」新增到数组中。
         // 将「乡镇区市名称」与「邮政编码」新增到数组中。 values.Add(new CascadingDropDownNameValue(sdr.GetSqlString(0).ToString(), sdr.GetSqlString(1).ToString()));
            values.Add(new CascadingDropDownNameValue(sdr.GetSqlString(0).ToString(), sdr.GetSqlString(1).ToString())); }
        } return values.ToArray();
        return values.ToArray();         }
    } }
}

运行结果:
 
                    
                     
                    
                 
                    
                 
                
 
 
         
     
     
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号