TREEVIEW点击文字展开
节点有SelectAction属性,它可以确定点击后的行为,选择Expande就可以了
绑定时
节点.SelectAction = TreeNodeSelectAction.Expand;
搞定!!!
void BindTree(TreeNodeCollection nds, int parentId)
{//项目栏树形菜单生成
TreeNode tn = null;
foreach (DataRow dr in BLL.Menu.TreeviewItem().Select("PId=" + parentId,"ListID asc"))
{
tn = new TreeNode(dr["Name"].ToString(), dr["id"].ToString(), null, dr["Url"].ToString(),"fmain");
//tn.ShowCheckBox = true;
nds.Add(tn);
if (BLL.Menu.ChildNodesCount(dr["PID"].ToString()) > 0)
tn.SelectAction = TreeNodeSelectAction.Expand;
BindTree(tn.ChildNodes, Convert.ToInt32(dr["id"]));
}
}
///
/// 子结点数
///
/// 父结点
/// 子结点数
public static int ChildNodesCount(string pid)
{
SqlParameter[] param1 ={
new SqlParameter("@PID", SqlDbType.Int),
new SqlParameter("@NodesCount",SqlDbType.Int)
};
param1[1].Direction = ParameterDirection.Output;
param1[0].Value = pid;
DAL.DBOperate.RunProcedure("OA_System_MenuChildNodesCount", param1);
return Convert.ToInt32(param1[1].Value);
}