标题:无限级下拉菜单
取消只看楼主
belin2000
Rank: 3Rank: 3
等 级:论坛游侠
威 望:5
帖 子:975
专家分:194
注 册:2004-6-2
结帖率:0
 问题点数:0 回复次数:1 
无限级下拉菜单

tlr_1 (表名)
Tlr_1_0 自动编号
Tlr_1_1 nchar(50)类别名称
Tlr_1_2 数字 对应Tlr_1_0 (大类为0,小类应其大类tlr_1_0)
Tlr_1_3 int 深度

if (!IsPostBack)
{
pweb_SQL pwebsql = new pweb_SQL();
DataTable dt = pwebsql.retabel("select * from tlr_1 order by tlr_1_3");
DataTable dt1 = new DataTable();
dt1.Columns.Add("tlr_1_0", typeof(int));
dt1.Columns.Add("tlr_1_1", typeof(string));
int i = 0;
while (dt.Rows.Count > 0 && i < dt.Rows.Count)
{
DataRow dr = dt.Rows[i];
if (dr["tlr_1_3"].ToString() == "1")
{
dt1.Rows.Add(new object[] { dr[0].ToString(), dr[1].ToString() });
dt.Rows.Remove(dr);
}
else
{
i++;
}

}
int n = 1;
int depth = Convert.ToInt32(pwebsql.fvalue("select max(tlr_1_3) from tlr_1"));
string sp = "│";
while (n < depth)
{
i = 0;
for (; i < dt.Rows.Count; i++)
{
int j = 0;
DataRow dr = dt.Rows[j];
if (int.Parse(dr["tlr_1_3"].ToString()) == n + 1)
{
DataRow dr1 = dt1.NewRow();
dr1.ItemArray = new object[] { dr[0].ToString(), sp + "├&nbsp;" + dr[1].ToString() };
int inrows = 0;
foreach (DataRow dr0 in dt1.Rows)
{
inrows++;
if (dr0[0].ToString() == dr["tlr_1_2"].ToString())
{
break;
}

}

dt1.Rows.InsertAt(dr1, inrows);
dt.Rows.Remove(dr);
}
else
{ j++; }
}
sp += "└";
n++;

}

//Response.Write(dt1.Rows.Count);
foreach (DataRow dr8 in dt1.Rows)
{
ListItem item = new ListItem();
item.Text = Server.HtmlDecode(dr8[1].ToString());
item.Value = dr8[0].ToString();
DropDownList1.Items.Add(item);
}
}
}

搜索更多相关主题的帖子: tlr Tlr SQL 菜单 
2007-03-27 18:34
belin2000
Rank: 3Rank: 3
等 级:论坛游侠
威 望:5
帖 子:975
专家分:194
注 册:2004-6-2
得分:0 

你调试下。。。思路是无限级的


59ita点com(我就爱TA)
2007-03-28 11:43



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-127259-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.049050 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved