62,041
社区成员
发帖
与我相关
我的任务
分享
private void bind()
{
string temp = "<ul class='simpleTree'>";
DataSet ds = db.getDs();
DataRow[] dr = ds.Tables[0].Select("department_code='001'");
Response.Write("为了测试,当前总行数为:" + "<a style='color=red'>"+ds.Tables[0].Rows.Count+"</a><div style='height=10px;background-color:white'></div>");
foreach (DataRow r in dr)
{
string name = r["department_name"].ToString();
string code = r["department_code"].ToString();
temp += "<li class='root' id='li1' name='" + name + "'><span id='s1' oncontextmenu = showMenu('" + i + "') name='" + name + "' class='" + code + "'>" + name + "</span>";
if (AddChildNode(ds, code) != "" || AddChildNode(ds, code)!=null)
{
temp += "<ul>" + AddChildNode(ds, code);
ds.Tables[0].Rows.Remove(r);
}
}
temp += "</ul>";
mytree.InnerHtml = temp;
}
public string AddChildNode(DataSet ds, string department_code)
{
i++;
string a = "";
DataRow[] dr = ds.Tables[0].Select("parent_department='" + department_code + "'");
int count = dr.Length;
if (dr != null)
{
foreach (DataRow r in dr)
{
string code = r["department_code"].ToString();
string name = r["department_name"].ToString();
a += "<li id='li" + i + "' class='" + code + "' name='" + name + "'><span id='s" + i + "' oncontextmenu = showMenu('" + i + "') name='" + name + "' class='" + code + "'>" + name + "</span></li>";
if (AddChildNode(ds, code) == "" || AddChildNode(ds, code) == null)
{
}
else
{
a += "<ul>" + AddChildNode(ds, code) + "</ul>";
}
}
}
return a;
}