- 爱易网页
-
ASP.NET教程
- (100分)分层次的Dropdownlist(C#)满意立刻给分
日期:2014-05-18 浏览次数:20472 次
(100分)求一个分层次的Dropdownlist(C#)满意立刻给分!
在项目中遇到这样一个问题,需要在显示一个多层次的DropdownList
形式如下:
A
--A1
--A2
B
--B2
---B23
从数据库中取得不同层次的(level=0,1,2)分成3层
请用C#语言实现下,谢谢!
------解决方案--------------------
http://blog.csdn.net/xbf321/archive/2007/05/23/1622674.aspx
------解决方案--------------------
<html>
<head>
<script>
var arrUnit = new Array();
arrUnit[0] = new Array( '0 ', "u01 ", "单位1 ");
arrUnit[1] = new Array( '0 ', "u02 ", "单位2 ");
arrUnit[2] = new Array( '0 ', "u03 ", "单位3 ");
var arrDept = new Array();
arrDept[0] = new Array( 'u01 ', 'd01 ', '部门1 ');
arrDept[1] = new Array( 'u01 ', 'd02 ', '部门2 ');
arrDept[2] = new Array( 'u02 ', 'd03 ', '部门3 ');
arrDept[3] = new Array( 'u02 ', 'd04 ', '部门4 ');
arrDept[4] = new Array( 'u03 ', 'd05 ', '部门5 ');
arrDept[5] = new Array( 'u03 ', 'd06 ', '部门6 ');
var arrEmp = new Array();
arrEmp[0] = new Array( "d01 ", "e01 ", "emp01 ");
arrEmp[1] = new Array( "d02 ", "e02 ", "emp03 ");
arrEmp[2] = new Array( "d03 ", "e03 ", "emp04 ");
function body_onload(){
var TD = GetParent(document.all( "s0 "), "TD ");
TD.innerHTML = MakeMenu(arrUnit, 0, 0, "s0 ");
TD = GetParent(document.all( "s1 "), "TD ");
TD.innerHTML = MakeMenu(arrDept, GetSelectValue(document.all( "s0 ")), 0, "s1 ");
TD = GetParent(document.all( "s2 "), "TD ");
TD.innerHTML = MakeMenu(arrEmp, GetSelectValue(document.all( "s1 ")), 0, "s2 ");
}
function GetParent(src, tag){
if (src && src.tagName!=tag){
return(GetParent(src.parentElement, tag));
}
return src;
}
function MakeMenu(arrSub, pValue, cValue, name){
var sHTML = " <select name= ' " + name + " ' onchange= 'SetSubMenu(this) ' > ";
sHTML += " <option value=0> <未选择> </option> ";
for (var i=0; i < arrSub.length; i++){
if (arrSub[i][0]==pValue){
var tag = (arrSub[i][1]==cValue)? " selected> ": "> ";
sHTML += " <option value= ' " + arrSub[i][1] + " ' " + tag + arrSub[i][2] + " </option> ";
}
}
sHTML += " </select> ";
return sHTML;
}
function GetSelectValue(oSelect){
if (oSelect.selectedIndex < 0) return 0;
return oSelect.options(oSelect.selectedIndex).value;
}
function SetSubMenu(pSelect){
var oOption, sValue;
if (pSelect.selectedIndex < 0) return;
switch (pSelect.name){
case "s0 ":
var TD = GetParent(document.all( "s1 "), "TD ");
TD.innerHTML = MakeMenu(arrDept, GetSelectValue(document.all( "s0 ")), "0 ", "s1 ");
TD = GetParent(document.all( "s2 "), "TD ");