Export (0) Print
Expand All

TreeNodeBinding.ShowCheckBox Property

Gets or sets a value indicating whether a check box is displayed next to a node to which the TreeNodeBinding object is applied.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public Nullable<bool> ShowCheckBox { get; set; }

Property Value

Type: System.Nullable<Boolean>
true to display a check box next to a node to which the TreeNodeBinding object is applied; otherwise, false. The default is false.

To provide multinode selection support in the TreeView control, you can display check boxes next to an image in the node. When the TreeView control is bound to a data source, use the ShowCheckBox property to specify the value to bind to the ShowCheckBox property of a TreeNode object. This binding relationship affects all TreeNode objects to which the TreeNodeBinding object is applied. The ShowCheckBox property is used to show or hide the check box for a node.

NoteNote

Although the ShowCheckBox property can be used to display check boxes, it is more common to use the ShowCheckBoxes property of the TreeView control. However, the ShowCheckBoxes property affects every node type that is specified by the property; therefore, the ShowCheckBox property is often used to override that setting for a node to which the TreeNodeBinding object is applied. You can selectively override the ShowCheckBox property by setting the ShowCheckBox property of each node directly.

The value of this property is stored in view state.

This section contains two code examples. The first code example demonstrates how to use the ShowCheckBox property to specify whether a check box is displayed for a node. The second code example provides sample XML data for the first code example.

The following example demonstrates how to use the ShowCheckBox property to specify whether a check box is displayed for a node. For this example to work correctly, you must copy the sample XML data, provided after this code example, to a file named Book.xml.


<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  void BookTreeView_CheckChanged(Object sender, TreeNodeEventArgs e)
  {

    // Display the nodes that have their check box selected.
    Message.Text = "You selected the following check boxes: ";

    foreach(TreeNode node in BookTreeView.CheckedNodes)
    {

      Message.Text += node.Text + " ";

    }

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeNodeBinding ShowCheckBox Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>TreeNodeBinding ShowCheckBox Example</h3>

      <asp:treeview id="BookTreeView" 
         datasourceid="BookXmlDataSource"
         expanddepth="2"
         OnTreeNodeCheckChanged="BookTreeView_CheckChanged"   
         runat="server">

        <DataBindings>
          <asp:TreeNodeBinding DataMember="Book" 
            TextField="Title"/>
          <asp:TreeNodeBinding DataMember="Chapter" 
            TextField="Heading"
            ShowCheckBox="True"/>
        </DataBindings>

      </asp:treeview>

      <asp:xmldatasource id="BookXmlDataSource"  
         datafile="Book.xml"
         runat="server">
      </asp:xmldatasource>

      <br/><br/>

      <asp:label id="Message"
        runat="server"/>

      <hr/>

      <asp:button id="SubmitButton"
        Text="Submit"
        runat="server"/>

    </form>
  </body>
</html>

The following code example provides sample XML data for the preceding code example.

<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>
    <Appendix Heading="Appendix A">
    </Appendix>
</Book>

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft