Sintaxis declarativa del control de servidor Web TreeView
Actualización: noviembre 2007
Muestra datos jerárquicos, como una tabla de contenido, en una estructura de árbol.
<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>
Comentarios
El control TreeView se utiliza para mostrar datos jerárquicos, como una tabla de contenido o un directorio de archivos, en una estructura de árbol y admite las siguientes características:
Compatibilidad con enlace de datos que permite enlazar los nodos del control a datos XML, de tablas o relacionales.
Compatibilidad con la navegación del sitio a través de la integración con el control SiteMapDataSource.
El texto del nodo se puede mostrar como texto sin formato o como hipervínculos.
Acceso mediante programación al modelo de objetos TreeView para crear árboles, rellenar nodos, definir propiedades, etc., de forma dinámica.
Población de nodos del cliente (en exploradores compatibles).
Capacidad para mostrar una casilla junto a cada nodo.
Capacidad de personalizar el aspecto mediante temas, imágenes definidas por el usuario y estilos.
Para obtener más información sobre el control TreeView, vea Información general sobre TreeView (Control de servidor Web).
Ejemplo
El ejemplo de código siguiente muestra cómo enlazar el control TreeView a un origen de datos 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>
Vea también
Referencia
Información general sobre TreeView (Control de servidor Web)