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 + "├ " + 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);
}
}
}