现在在实现二级连动或是三级连动方面,都是采用ajax来完成的。网上的例子也很多。 我采用的是AjaxPro来完的。 如何配置AjaxPro我就不说了。
BigClassid 前台页面
<script type="text/javascript">    
function ShowCity(id)    
{    
var result = chen.getCityList(id).value;    
var ddlcity = document.getElementById("ddlCity");    
ddlcity.length=0;    
for(var i=0; i<result.Rows.length; i++)    
{    
ddlcity.options.add(new Option(result.Rows[i].SmallClass,result.Rows[i].id));    
}    
}    
</script>    
</head>    
<body>    
<form id="form1" runat="server">    
<p>    
省份:<asp:DropDownList ID="ddlPro" runat="server">    
</asp:DropDownList>    
市区:<asp:DropDownList ID="ddlCity" runat="server">    
</asp:DropDownList>    
</p>    
<div>    

</div>    
</form>    
</body>    
<script type="text/javascript">
function ShowCity(id)
{
var result = chen.getCityList(id).value;    
var ddlcity = document.getElementById("ddlCity");    
ddlcity.length=0;    
for(var i=0; i<result.Rows.length; i++)
{
ddlcity.options.add(new Option(result.Rows[i].SmallClass,result.Rows[i].id));    
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<p>
省份:<asp:DropDownList ID="ddlPro" runat="server">
</asp:DropDownList>
市区:<asp:DropDownList ID="ddlCity" runat="server">
</asp:DropDownList>
</p>
<div>

</div>
</form>
</body>
后台:
InBlock.gif[AjaxPro.AjaxNamespace( "chen")]    
InBlock.gif public partial class ddlTwo : System.Web.UI.Page    
InBlock.gif{    
InBlock.gif protected void Page_Load( object sender, EventArgs e)    
InBlock.gif{    
InBlock.gifAjaxPro.Utility.RegisterTypeForAjax( typeof(ddlTwo));    
InBlock.gif
InBlock.gifSqlConnection conn = new SqlConnection( "server=.; uid=sa; pwd=chen123; database=C_News; ");    
InBlock.gifconn.Open();    
InBlock.gifSqlCommand cmd = new SqlCommand("", conn);    
InBlock.gif string strsql = "select * from C_BigClass";    
InBlock.gifcmd.CommandText = strsql;    
InBlock.gifSqlDataAdapter da = new SqlDataAdapter();    
InBlock.gifda.SelectCommand = cmd;    
InBlock.gifDataTable dt = new DataTable();    
InBlock.gifda.Fill(dt);    
InBlock.gif
InBlock.gif this.ddlPro.DataSource = dt;    
InBlock.gif this.ddlPro.DataValueField = "id";    
InBlock.gif this.ddlPro.DataTextField = "BigClass";    
InBlock.gif this.ddlPro.DataBind();    
InBlock.gif
InBlock.gif this.ddlPro.Attributes[ "onchange"] = "ShowCity(this.options[selectedIndex].value)";    
InBlock.gif
InBlock.gifconn.Close();    
InBlock.gif}    
InBlock.gif
InBlock.gif[AjaxPro.AjaxMethod]    
InBlock.gif public DataTable getCityList( int id)    
InBlock.gif{    
InBlock.gifHashtable ht = new Hashtable();    
InBlock.gif
InBlock.gifSqlConnection conn = new SqlConnection( "server=.; uid=sa; pwd=chen123; database=C_News; ");    
InBlock.gifconn.Open();    
InBlock.gifSqlCommand cmd = new SqlCommand("", conn);    
InBlock.gif string strsql = "select * from C_SmallClass where BigClassid="+id+"";    
InBlock.gifcmd.CommandText = strsql;    
InBlock.gifSqlDataAdapter da = new SqlDataAdapter();    
InBlock.gifda.SelectCommand = cmd;    
InBlock.gifDataTable dt = new DataTable();    
InBlock.gifda.Fill(dt);    
InBlock.gif
InBlock.gif return dt;    
InBlock.gif}    
InBlock.gif}

  如果我们要进行三级或四级连动,其实很简单,只要在Page_load下面this.ddlPro.Attributes["onchange"] = "ShowCity(this.options[selectedIndex].value)"; 的下面为每个下拉框都加一个方法就行了。只不过多写几个public DataTable getCityList(int id)的程序。