1. Generate a TREEVIEW and load all nodes at a time
/// <Summary>
/// Initialize the topic tree
/// </Summary>
Private void initTree ()
{
// Obtain the root Column
Channel rootChannel = CmsHttpContext. Current. RootChannel;
Int dc = rootChannel. Channels. Count;
// Clear the original directory tree
ChannelView. Nodes. Clear ();
TreeNode rootNode = new TreeNode ();
RootNode. Text = "topic tree ";
RootNode. Value = rootChannel. Guid;
// RootNode. NavigateUrl = "~ /Module/ChannelInfoManage/ChannelManage. aspx? Guid = "+ rootChannel. Guid;
RootNode. Target = "ChannelManage ";
// Call a function to generate a subnode
CreateTree (rootChannel, rootNode );
// ChannelView is a TREEVIEW object declared in ASPX.
ChannelView. Nodes. Add (rootNode );
ChannelView. ExpandDepth = 1;
}
/// <Summary>
/// Create a column tree
/// </Summary>
/// <Param name = "rootChannel"> root column </param>
/// <Param name = "rootNode"> root node </param>
Public void CreateTree (Channel rootChannel, TreeNode rootNode)
{
If (rootChannel. Channels. Count> 0 & rootChannel. Channels! = Null)
{
Foreach (Channel subChannel in rootChannel. Channels)
{
TreeNode subNode = new TreeNode ();
// Display name of the node in the TREEVIEW Node
SubNode. Text = subChannel. Name;
// Set the node Value
SubNode. Value = subChannel. Guid;
// SubNode. NavigateUrl = "~ /Module/ChannelInfoManage/ChannelManage. aspx? Guid = "+ subChannel. Guid;
SubNode. Target = "ChannelManage ";
// Check box before the node
SubNode. ShowCheckBox = true;
// Obtain a value indicating whether the check box is selected
SubNode. Checked = subChannel. IsHiddenModePublished;
// Add the root node to the subnode
RootNode. ChildNodes. Add (subNode );
// Recursive call to generate subnodes
CreateTree (subChannel, subNode );
}
}
}
Ii. Dynamic Loading and generation of TREEVIEW. Click a node to dynamically generate the node under it.
Protected void Page_Load (object sender, EventArgs e)
{
If (! Page. IsPostBack)
{
// Set the submit button to confirm the attributes
SubmitButtonInit (submitButton );
// Initialize the topic tree
Channel rootChannel = context. RootChannel;
TreeNode rootNode = new TreeNode ();
RootNode. Text = rootChannel. Name;
RootNode. Value = rootChannel. Guid;
// Set the dynamic filling Node
RootNode. PopulateOnDemand = true;
// Set the node to collapse
RootNode. Expanded = false;
// TREEVIEW is added to the root node
ChannelView. Nodes. Add (rootNode );
}
}
/// <Summary>
/// Initialize the confirmation button to check whether a column is hidden on the client
/// </Summary>
Private void submitButtonInit (Button submitButton)
{
SubmitButton. Attributes. Add ("onClick", "return confirm ('Are you sure you want to change the hidden state of the selected subtopic? ')");
}
// Implement the function of dynamically filling the TREEVIEW
Protected void ChannelView_TreeNodePopulate (object sender, TreeNodeEventArgs e)
{
Channel curChannel = null;
ChannelCollection channelCol = null;
CurChannel = context. Searches. GetByGuid (e. Node. Value) as Channel;
ChannelCol = curChannel. Channels;
If (channelCol! = Null & channelCol. Count> 0)
{
Foreach (Channel subChannel in channelCol)
{
TreeNode node = new TreeNode ();
Node. Text = subChannel. Name;
Node. Value = subChannel. Guid;
Node. ShowCheckBox = true;
Node. Checked = channelOperater. IsChannelHided (subChannel );
Node. PopulateOnDemand = true;
Node. Expanded = false;
E. Node. ChildNodes. Add (node );
}
}
}
3. Check whether the checkbox before capturing the TREEVIEW node is selected or canceled.
TREEVIEW ChannelView = new TREEVIEW ();
ChannelView. CheckedNodes
The CheckedNodes attribute of treeview represents the node set TREENODECOLLECTION selected by the check box before the node.
For the set of nodes that have canceled the check boxes
TreeNodeCollection tc = new TreeNodeCollection ();
Generate the following:
Int I = 0;
Protected void ChannelView_TreeNodeCheckChanged (object sender, TreeNodeEventArgs e)
{
If (e. Node. Checked = false)
Tc. Add (e. Node );
}