搜档网
当前位置:搜档网 › TreeView後台绑定数据源

TreeView後台绑定数据源

treeview后台绑定数据源2010-09-08 10:13




后台:

public void DisplayUserMenu()

{

https://www.sodocs.net/doc/101760489.html,SysFunUpdate.Nodes.Clear();

//得到系统菜单表中所有的第一级菜单


DataSet ds = DbHelperSQL.Query("select * from dbo.shopClass where shopid="+shopid+" and father=0 order by classorder");


for (int i = 0; i < ds.Tables[0].Rows.Count; i++)

{

//得到第一层节点的Id

string nodeId = ds.Tables[0].Rows[i]["shopClassid"].ToString();

//得到第一层节点的显示名称

string displayName = ds.Tables[0].Rows[i]["shopClassname"].ToString();

//根据节点信息创建一层节点

TreeNode fatherNode = CreateTreeNode(displayName, nodeId, "images/up01.gif");

//if (nodeId != "143")

//{

// fatherNode.Target = "";

// fatherNode.NavigateUrl = "DianXinAnli.aspx?ColId=" + nodeId;

//}


CreateChildTree(nodeId, fatherNode);

https://www.sodocs.net/doc/101760489.html,SysFunUpdate.Nodes.Add(fatherNode);

}


////选中的子菜单其父节点打开

//if (hidNodeId.Value.ToString() != "" && hidNodeId.Value.ToString().Length > 3)

//{

// foreach (TreeNode treeNode in https://www.sodocs.net/doc/101760489.html,SysFunUpdate.Nodes)

// {


// if (hidNodeId.Value.ToString().IndexOf(treeNode.Value.ToString()) == 0)

// { treeNode.Expand(); }

// }

//}

}

private TreeNode CreateTreeNode(string strText, string strId, string strImage)

{

TreeNode newNode = new TreeNode();

newNode.Text = strText;

newNode.Value = strId;

newNode.ImageUrl = strImage;

return newNode;

}

//创建第二级节点

public void CreateChildTree(string nodeId, TreeNode fatherNode)

{

//在三层下实现获得父级节点为nodeId的所有子节点


DataSet ds = DbHelperSQL.Query("select * from dbo.shopClass where shopClassid=" + nodeId + " order by classorder");


for (int i = 0; i < ds.Tables[0].Rows.Count; i++)

{

//得到第二层节点Id

string childNodeId = ds.Tables[0].Rows[i]["shopClassid"].ToString();

//得到第二层节点的显示名称

string childDisplayName = ds.Tables[0].Rows[i]["shopClassname"].ToString();


//根据节点信息,创建第二层节点

TreeNode childNode = CreateTreeNode(childDisplayName, childNodeId, "images/up01.gif");

childNode.Target = "";

childNode.NavigateUrl = "shopGoodsSearch.aspx?ColId=" + childNodeId;


//将子节点加入到父节点中

AddTree(fatherNode, childNode);

}

}

//将子节点加入到父节点中

private void AddTree(TreeNode fatherNode, TreeNode childNode)

{

fatherNode.ChildNodes.Add(childNode);

}



相关主题