CS :
1
protected
void
Page_Load(
object
sender, System.EventArgs e)
2
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
3
if (!IsPostBack)
4![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
5
DataSet ds = new DataSet();
6
ds.ReadXml(Server.MapPath("DataSource.xml"));
7
for(int i = 0;i <ds.Tables[0].Rows.Count ;i++)
8![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
9
DataRow dr = ds.Tables[0].Rows[i];
10![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Want.Text += String.Format("Group[Groupcount++] = new Array(\"
{0}\",\"
{1}\",\"
{2}\");\n", dr["v_Source"],dr["v_GroupName"].ToString(), dr["v_title"].ToString());
11
if (SourceList1.Items.FindByText(dr["v_Source"].ToString()) == null)
12![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
13
SourceList1.Items.Add(dr["v_Source"].ToString());
14
}
15
}
16
}
17
}
ASPX:
<%
@ Page language="c#" Inherits="TowDropDownList.TowDropDownList" CodeFile="TreeDropDownList.aspx.cs"
%>
<!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
>
<
HTML
>
<
HEAD
>
<
title
>
TreeDropDownList
</
title
>
<
meta
content
="Microsoft Visual Studio 7.0"
name
="GENERATOR"
>
<
meta
content
="C#"
name
="CODE_LANGUAGE"
>
<
meta
content
="JavaScript"
name
="vs_defaultClientScript"
>
<
meta
content
="http://schemas.microsoft.com/intellisense/ie5"
name
="vs_targetSchema"
>
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
<
script
language
="javascript"
>
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
var Wantcount;
var Groupcount;
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Groupcount=0;
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Group = new Array();
<asp:Literal id="Want" runat="server"></asp:Literal>
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
function changelocation1(locationid)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
document.submit.DirectionList1.length = 0;
document.submit.WantList1.length = 0;
var locationid=locationid;
var i;
var flag;
var j;
for (i=0;i<Groupcount; i++)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (Group[i][0] == locationid)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
flag = true;
for (j =0;j<document.submit.DirectionList1.length;j++)
if (document.submit.DirectionList1[j].value == Group[i][1])
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
flag = false;
break;
}
if (flag)
document.submit.DirectionList1.options[document.submit.DirectionList1.length]
= new Option(Group[i][1], Group[i][1]);
}
}
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
function changelocation11(locationid, direction)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
document.submit.WantList1.length = 0;
var locationid=locationid;
var i;
var flag;
var j;
for (i=0;i<Groupcount;i++)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (Group[i][0] == locationid && Group[i][1] == direction)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
flag = true;
for (j=0;j<document.submit.WantList1.length;j++)
if (document.submit.WantList1[j].value == Group[i][2])
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
flag = false;
break;
}
if (flag)
document.submit.WantList1.options[document.submit.WantList1.length]
= new Option(Group[i][2], Group[i][2]);
}
}
}
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
</
script
>
</
HEAD
>
<
BODY
>
<
form
id
="submit"
method
="post"
runat
="server"
>
<
TABLE
style
="Z-INDEX: 101; LEFT: 184px; POSITION: absolute; TOP: 144px"
>
<
TR
>
<
TD
style
="WIDTH: 115px; HEIGHT: 17px"
align
="middle"
>
求职意向:
</
TD
>
<
TD
style
="HEIGHT: 17px"
>
<
asp:dropdownlist
id
="SourceList1"
runat
="server"
DataTextField
="v_source"
DataValueField
="v_source"
onchange
="changelocation1(document.submit.SourceList1.options[document.submit.SourceList1.selectedIndex].value);changelocation11(document.submit.SourceList1.options[document.submit.SourceList1.selectedIndex].value,document.submit.DirectionList1.options[document.submit.DirectionList1.selectedIndex].value)"
Width
="100px"
></
asp:dropdownlist
>
<
asp:dropdownlist
id
="DirectionList1"
runat
="server"
DataValueField
="v_GroupName"
onchange
="changelocation11(document.submit.SourceList1.options[document.submit.SourceList1.selectedIndex].value,document.submit.DirectionList1.options[document.submit.DirectionList1.selectedIndex].value)"
Width
="100px"
></
asp:dropdownlist
>
<
asp:dropdownlist
id
="WantList1"
runat
="server"
DataValueField
="v_title"
Width
="100px"
></
asp:dropdownlist
></
TD
>
</
TR
>
</
TABLE
>
</
form
>
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
<
script
language
="javascript"
>
changelocation1(document.submit.SourceList1.options[document.submit.SourceList1.selectedIndex].value);
changelocation11(document.submit.SourceList1.options[document.submit.SourceList1.selectedIndex].value,document.submit.DirectionList1.options[document.submit.DirectionList1.selectedIndex].value)
</
script
>
</
BODY
>
</
HTML
>
XML:
<
DataSource
>
<
Data
>
<
v_Source
>
计算机类
</
v_Source
>
<
v_GroupName
>
软件
</
v_GroupName
>
<
v_title
>
程序员
</
v_title
>
</
Data
>
<
Data
>
<
v_Source
>
计算机类
</
v_Source
>
<
v_GroupName
>
软件
</
v_GroupName
>
<
v_title
>
系统分析员
</
v_title
>
</
Data
>
<
Data
>
<
v_Source
>
计算机类
</
v_Source
>
<
v_GroupName
>
软件
</
v_GroupName
>
<
v_title
>
项目经理
</
v_title
>
</
Data
>
<
Data
>
<
v_Source
>
计算机类
</
v_Source
>
<
v_GroupName
>
硬件
</
v_GroupName
>
<
v_title
>
网络工程师
</
v_title
>
</
Data
>
<
Data
>
<
v_Source
>
计算机类
</
v_Source
>
<
v_GroupName
>
硬件
</
v_GroupName
>
<
v_title
>
计算机维护
</
v_title
>
</
Data
>
<
Data
>
<
v_Source
>
计算机类
</
v_Source
>
<
v_GroupName
>
数据库
</
v_GroupName
>
<
v_title
>
数据库开发
</
v_title
>
</
Data
>
<
Data
>
<
v_Source
>
计算机类
</
v_Source
>
<
v_GroupName
>
数据库
</
v_GroupName
>
<
v_title
>
数据库管理
</
v_title
>
</
Data
>
<
Data
>
<
v_Source
>
行政/管理类
</
v_Source
>
<
v_GroupName
>
行政
</
v_GroupName
>
<
v_title
>
文秘
</
v_title
>
</
Data
>
<
Data
>
<
v_Source
>
行政/管理类
</
v_Source
>
<
v_GroupName
>
行政
</
v_GroupName
>
<
v_title
>
助理
</
v_title
>
</
Data
>
<
Data
>
<
v_Source
>
行政/管理类
</
v_Source
>
<
v_GroupName
>
管理
</
v_GroupName
>
<
v_title
>
总经理
</
v_title
>
</
Data
>
<
Data
>
<
v_Source
>
行政/管理类
</
v_Source
>
<
v_GroupName
>
管理
</
v_GroupName
>
<
v_title
>
部门经理
</
v_title
>
</
Data
>
<
Data
>
<
v_Source
>
行政/管理类
</
v_Source
>
<
v_GroupName
>
管理
</
v_GroupName
>
<
v_title
>
总监
</
v_title
>
</
Data
>
</
DataSource
>
转载于:https://www.cnblogs.com/caviare/archive/2006/12/28/605749.html