树状图 无限级 递归
要做一个活的导航
代码如下:
string myTree = "{";
JLUserBLL bll = new JLUserBLL();
DataTable table = bll.PassValue();
DataView dv = new DataView(table);
string loginUser = this.loginUser.username;
var list = bll.GetMenu(loginUser);
string tree = "";
foreach (var item in list)
{
dv.RowFilter = "id=" + item.ChannelId + "";
tree = TreeDataBind(dv);
}
tree = tree.Substring(0, tree.Length - 1);
tree += "}";
public string TreeDataBind(DataView dv)
{
foreach (DataRowView drv in dv)
{
myTree += "["; //创建一个新的节点
//为新的借点设置属性
myTree += drv["DeptName"].ToString() + ",";
myTree += drv["ParentId"].ToString() + ",";
myTree += drv["id"].ToString() + ",";
myTree += drv["DeptLevel"].ToString();
myTree += "],";
//过滤数据视图 父类id = 上一级的tid
dv.RowFilter = "id=" + drv["ParentId"].ToString();
//自己调用自己
de.Add(dement);
TreeDataBind(dv);
}
de