📄 tvexample.aspx.cs
字号:
#region Using Directives
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.Web.UI.WebControls;
#endregion Using Directives
namespace Mike.Elliott.Articles.TreeView
{
public class TVExample : System.Web.UI.Page
{
protected Microsoft.Web.UI.WebControls.TreeView tvControl;
/// <summary>
/// Callback invoked when the page is loaded.
/// </summary>
/// <param name="sender">Invoker of the callback.</param>
/// <param name="e">An <see cref="EventArgs"/> type.</param>
private void Page_Load( object sender, System.EventArgs e )
{
// Create the root tree node.
TreeNode root = new TreeNode();
root.Text = "Root Parent Node";
root.NodeData = "SomeId=1000;Name=Mike Elliott";
// Create a child node.
TreeNode tn = new TreeNode();
tn.Text = "Child 1 of Root Parent";
tn.NodeData = "SomeId=1001;Name=Avyant, Inc.";
// Add the child to the root node.
root.Nodes.Add( tn );
// Create another child node.
tn = new TreeNode();
tn.Text = "Child 2 or Root Parent";
tn.NodeData = "SomeId=1002;Name=Chip Oxendine";
// Create a grandchild node and add it to its parent.
TreeNode cn = new TreeNode();
cn.Text = "Grandchild of Root Parent";
cn.NodeData = "SomeId=1003;Name=Mike Elliott";
tn.Nodes.Add( cn );
// Add the child to the root node.
root.Nodes.Add( tn );
root.Expanded = true;
// Add all the nodes to the tree view.
this.tvControl.Nodes.Add( root );
this.OverRideServerEvents();
}
/// <summary>
/// Overrides the server-side events for which we want to
/// handle on the client.
/// </summary>
private void OverRideServerEvents()
{
// Create and wire up the javascript event handlers.
//
string clickHandler = "TVIndexChanged();";
this.tvControl.Attributes.Add( "onselectedindexchange", clickHandler );
clickHandler = "TVNodeExpand();";
this.tvControl.Attributes.Add( "onexpand", clickHandler );
clickHandler = "TVNodeCollapse();";
this.tvControl.Attributes.Add( "oncollapse", clickHandler );
clickHandler = "TVDoubleClick();";
this.tvControl.Attributes.Add( "ondblclick", clickHandler );
clickHandler = "TVRightClick();";
this.tvControl.Attributes.Add( "oncontextmenu", clickHandler );
}
#region Web Form Designer generated code
override protected void OnInit( EventArgs e )
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler( this.Page_Load );
}
#endregion Web Form Designer generated code
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -