<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %> <%@ Import Namespace="System.Collections" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>二维数组显示到下拉列表中</title> <Script Language="C#" Runat="server"> ArrayList list1 = new ArrayList(); void Page_Load(object sender, EventArgs e) { list1.Add(new string[] { "1", "0", "a1" }); list1.Add(new string[] { "2", "1", "a11" }); list1.Add(new string[] { "3", "0", "b1" }); list1.Add(new string[] { "4", "2", "a111" }); list1.Add(new string[] { "5", "3", "b11" }); addOptions("0", 0); } void addOptions(string _parentid, int _depth) { string _optiontext = ""; string[] lstr; int i, j; for (i = 0; i < list1.Count; i++) { lstr = (string[])list1[i]; if (_parentid == lstr[1]) { for (j = 0; j <= _depth; j++) { if (j == 0) _optiontext = "|"; else _optiontext += " |"; } _optiontext += "─" + lstr[2]; ddltest1.Items.Add(new ListItem(_optiontext, lstr[0])); addOptions(lstr[0], _depth + 1); } } } </Script> </head> <body> <form id="form1" runat="server"> <asp:DropDownList ID="ddltest1" runat="server"></asp:DropDownList> </form> </body> </html> 效果如下: