TreeView Web 服务器控件声明性语法
更新:2007 年 11 月
以树形结构显示分层数据,如目录。
<asp:TreeView
AccessKey="string"
AutoGenerateDataBindings="True|False"
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
Inset|Outset"
BorderWidth="size"
CollapseImageToolTip="string"
CollapseImageUrl="uri"
CssClass="string"
DataSource="string"
DataSourceID="string"
EnableClientScript="True|False"
Enabled="True|False"
EnableTheming="True|False"
EnableViewState="True|False"
ExpandDepth="string|FullyExpand|0|1|2|3|4|5|6|7|8|9|10|11|12|13|
14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30"
ExpandImageToolTip="string"
ExpandImageUrl="uri"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
ID="string"
ImageSet="Custom|XPFileExplorer|Msdn|WindowsHelp|Simple|Simple2|
BulletedList|BulletedList2|BulletedList3|BulletedList4|
Arrows|News|Contacts|Inbox|Events|Faq"
LineImagesFolder="string"
MaxDataBindDepth="integer"
NodeIndent="integer"
NodeWrap="True|False"
NoExpandImageUrl="uri"
OnDataBinding="DataBinding event handler"
OnDataBound="DataBound event handler"
OnDisposed="Disposed event handler"
OnInit="Init event handler"
OnLoad="Load event handler"
OnPreRender="PreRender event handler"
OnSelectedNodeChanged="SelectedNodeChanged event handler"
OnTreeNodeCheckChanged="TreeNodeCheckChanged event handler"
OnTreeNodeCollapsed="TreeNodeCollapsed event handler"
OnTreeNodeDataBound="TreeNodeDataBound event handler"
OnTreeNodeExpanded="TreeNodeExpanded event handler"
OnTreeNodePopulate="TreeNodePopulate event handler"
OnUnload="Unload event handler"
PathSeparator="string"
PopulateNodesFromClient="True|False"
runat="server"
ShowCheckBoxes="None|Root|Parent|Leaf|All"
ShowExpandCollapse="True|False"
ShowLines="True|False"
SkinID="string"
SkipLinkText="string"
Style="string"
TabIndex="integer"
Target="string"
ToolTip="string"
Visible="True|False"
Width="size"
>
<DataBindings>
<asp:TreeNodeBinding
DataMember="string"
Depth="integer"
FormatString="string"
ImageToolTip="string"
ImageToolTipField="string"
ImageUrl="uri"
ImageUrlField="string"
href="uri"
hrefField="string"
PopulateOnDemand="True|False"
SelectAction="Select|Expand|SelectExpand|None"
ShowCheckBox="string"
Target="string"
TargetField="string"
Text="string"
TextField="string"
ToolTip="string"
ToolTipField="string"
Value="string"
ValueField="string"
/>
</DataBindings>
<HoverNodeStyle />
<LeafNodeStyle
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
Groove|Ridge|Inset|Outset"
BorderWidth="size"
ChildNodesPadding="size"
CssClass="string"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
Medium|Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
HorizontalPadding="size"
ImageUrl="uri"
NodeSpacing="size"
OnDisposed="Disposed event handler"
VerticalPadding="size"
Width="size"
/>
<LevelStyles>
<asp:TreeNodeStyle
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|
Double|Groove|Ridge|Inset|Outset"
BorderWidth="size"
ChildNodesPadding="size"
CssClass="string"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|
X-Small|Small|Medium|Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
HorizontalPadding="size"
ImageUrl="uri"
NodeSpacing="size"
OnDisposed="Disposed event handler"
VerticalPadding="size"
Width="size"
/>
</LevelStyles>
<Nodes>
<asp:TreeNode
Checked="True|False"
Expanded="string"
ImageToolTip="string"
ImageUrl="uri"
href="uri"
PopulateOnDemand="True|False"
SelectAction="Select|Expand|SelectExpand|None"
Selected="True|False"
ShowCheckBox="string"
Target="string"
Text="string"
ToolTip="string"
Value="string"
>
</asp:TreeNode>
</Nodes>
<NodeStyle
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
Groove|Ridge|Inset|Outset"
BorderWidth="size"
ChildNodesPadding="size"
CssClass="string"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
Medium|Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
HorizontalPadding="size"
ImageUrl="uri"
NodeSpacing="size"
OnDisposed="Disposed event handler"
VerticalPadding="size"
Width="size"
/>
<ParentNodeStyle
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
Groove|Ridge|Inset|Outset"
BorderWidth="size"
ChildNodesPadding="size"
CssClass="string"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
Medium|Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
HorizontalPadding="size"
ImageUrl="uri"
NodeSpacing="size"
OnDisposed="Disposed event handler"
VerticalPadding="size"
Width="size"
/>
<RootNodeStyle
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
Groove|Ridge|Inset|Outset"
BorderWidth="size"
ChildNodesPadding="size"
CssClass="string"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
Medium|Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
HorizontalPadding="size"
ImageUrl="uri"
NodeSpacing="size"
OnDisposed="Disposed event handler"
VerticalPadding="size"
Width="size"
/>
<SelectedNodeStyle
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
Groove|Ridge|Inset|Outset"
BorderWidth="size"
ChildNodesPadding="size"
CssClass="string"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Overline="True|False"
Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|
Medium|Large|X-Large|XX-Large"
Font-Strikeout="True|False"
Font-Underline="True|False"
ForeColor="color name|#dddddd"
Height="size"
HorizontalPadding="size"
ImageUrl="uri"
NodeSpacing="size"
OnDisposed="Disposed event handler"
VerticalPadding="size"
Width="size"
/>
</asp:TreeView>
备注
TreeView 控件用于以树形结构显示分层数据(如目录或文件目录),并支持下列功能:
支持数据绑定,从而允许将该控件的节点绑定到 XML、表格或关系数据。
通过与 SiteMapDataSource 控件集成提供对站点导航的支持。
可以显示为纯文本或超链接的节点文本。
通过编程访问 TreeView 对象模型,动态地创建树、填充节点以及设置属性等。
客户端节点填充(在支持的浏览器上)。
能够在每个节点旁边显示复选框。
能够通过主题、用户定义的图像和样式自定义外观。
有关 TreeView 控件的更多信息,请参见 TreeView Web 服务器控件概述。
示例
下面的代码示例演示如何将 TreeView 控件绑定到 XML 数据源。
<asp:TreeView id="BookTreeView" dataSourceID="BookXmlDataSource" runat="server">
<DataBindings>
<asp:TreeNodeBinding DataMember="Book" TextField="Title"/>
<asp:TreeNodeBinding DataMember="Chapter" TextField="Heading"/>
<asp:TreeNodeBinding DataMember="Section" TextField="Heading"/>
</DataBindings>
</asp:TreeView>
<asp:XmlDataSource id="BookXmlDataSource" runat="server">
<Data>
<Book Title="Book Title">
<Chapter Heading="Chapter 1">
<Section Heading="Section 1">
</Section>
<Section Heading="Section 2">
</Section>
</Chapter>
<Chapter Heading="Chapter 2">
<Section Heading="Section 1">
</Section>
</Chapter>
</Book>
</Data>
</asp:XmlDataSource>
<asp:TreeView id="BookTreeView" dataSourceID="BookXmlDataSource" runat="server">
<DataBindings>
<asp:TreeNodeBinding DataMember="Book" TextField="Title"/>
<asp:TreeNodeBinding DataMember="Chapter" TextField="Heading"/>
<asp:TreeNodeBinding DataMember="Section" TextField="Heading"/>
</DataBindings>
</asp:TreeView>
<asp:XmlDataSource id="BookXmlDataSource" runat="server">
<Data>
<Book Title="Book Title">
<Chapter Heading="Chapter 1">
<Section Heading="Section 1">
</Section>
<Section Heading="Section 2">
</Section>
</Chapter>
<Chapter Heading="Chapter 2">
<Section Heading="Section 1">
</Section>
</Chapter>
</Book>
</Data>
</asp:XmlDataSource>