1. asp net2.0 TreeView 客户端按需展开,其实msdn里就有,copy出来看着方便点
设置节点的PopulateOnDemand="True" SelectAction="Expand"属性
后台treeView TreeNodePopulate事件:
protected void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e)
{
if (e.Node.Value == "9") return;
TreeNode NewNode = new TreeNode(e.Node.Value, (int.Parse(e.Node.Value)+1).ToString());
// Set the PopulateOnDemand property to true so that the child nodes can be
// dynamically populated.
NewNode.PopulateOnDemand = true;
// Set additional properties for the node.
NewNode.SelectAction = TreeNodeSelectAction.Expand;
// Add the new node to the ChildNodes collection of the parent node.
e.Node.ChildNodes.Add(NewNode);
}
{
if (e.Node.Value == "9") return;
TreeNode NewNode = new TreeNode(e.Node.Value, (int.Parse(e.Node.Value)+1).ToString());
// Set the PopulateOnDemand property to true so that the child nodes can be
// dynamically populated.
NewNode.PopulateOnDemand = true;
// Set additional properties for the node.
NewNode.SelectAction = TreeNodeSelectAction.Expand;
// Add the new node to the ChildNodes collection of the parent node.
e.Node.ChildNodes.Add(NewNode);
}
2. TreeView 客户端全选
通过js实现的选择母节点check后,所有字节点也选中




















































使用:加入treeView客户端点击事件OnClick
<asp:TreeView ID="TreeView1" runat="server" OnTreeNodePopulate="TreeView1_TreeNodePopulate"
ShowCheckBoxes="All" onclick="client_OnTreeNodeChecked();" >
结合第一条动态按需展开:
因js遍历时,按需获取的node在展开之前无法遍历到,
新展开的节点默认都没有选中
因此需要在动态展开时继承其母节点的选中状态
修改后台TreeView1_TreeNodePopulate事件
加入:
TreeNode NewNode = new TreeNode(e.Node.Value, (int.Parse(e.Node.Value) + 1).ToString());
if (e.Node.Checked == true) NewNode.Checked = true; //继承母节点选中状态