TreeNodeBinding.PopulateOnDemand プロパティ

定義

TreeNodeBinding オブジェクトが適用されるノードに動的にデータを設定するかどうかを示す値を取得または設定します。

public:
 property bool PopulateOnDemand { bool get(); void set(bool value); };
public bool PopulateOnDemand { get; set; }
member this.PopulateOnDemand : bool with get, set
Public Property PopulateOnDemand As Boolean

プロパティ値

TreeNodeBinding オブジェクトが適用されるノードに動的にデータを設定する場合は true。それ以外の場合は false。 既定値は、false です。

このセクションには、2 つのコード例が含まれています。 最初のコード例では、 プロパティをShowCheckBox使用して、ノードのチェック ボックスを表示するかどうかを指定する方法を示します。 2 番目のコード例では、最初のコード例のサンプル XML データを提供します。

次の例では、 プロパティをShowCheckBox使用して、ノードのチェック ボックスを表示するかどうかを指定する方法を示します。 この例を正しく機能させるには、このコード例の後に提供されるサンプル XML データを 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 Page_Load(Object sender, EventArgs e)
  {

    // Create a TreeNodeBinding object and set its 
    // properties.
    TreeNodeBinding binding = new TreeNodeBinding();
    binding.DataMember = "Section";
    binding.Depth = 2;
    binding.TextField = "Heading";

    // Set the PopulateOnDemand property of the
    // TreeNodeBinding object programmatically.
    binding.PopulateOnDemand = false;

    // Add the TreeNodeBinding object to the DataBindings
    // collection of the TreeView control.
    BookTreeView.DataBindings.Add(binding);

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeNodeBinding PopulateOnDemand Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeNodeBinding PopulateOnDemand Example</h3>
    
      <asp:TreeView id="BookTreeView" 
        DataSourceID="BookXmlDataSource"
        ExpandDepth="2"  
        runat="server">
         
        <DataBindings>
          <asp:TreeNodeBinding DataMember="Book" 
            TextField="Title"/>
          <asp:TreeNodeBinding DataMember="Chapter" 
            TextField="Heading"
            PopulateOnDemand="False"/>
          <asp:TreeNodeBinding DataMember="Section" 
            TextField="Heading"/>
        </DataBindings>
         
      </asp:TreeView>
      
      <asp:XmlDataSource id="BookXmlDataSource"  
        DataFile="Book.xml"
        runat="server">
      </asp:XmlDataSource>
    
    </form>
  </body>
</html>

<%@ Page Language="VB" %>

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

  Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    ' Create a TreeNodeBinding object and set its 
    ' properties.
    Dim binding As TreeNodeBinding = New TreeNodeBinding
    binding.DataMember = "Section"
    binding.Depth = 2
    binding.TextField = "Heading"

    ' Set the PopulateOnDemand property of the
    ' TreeNodeBinding object programmatically.
    binding.PopulateOnDemand = False

    ' Add the TreeNodeBinding object to the DataBindings
    ' collection of the TreeView control.
    BookTreeView.DataBindings.Add(binding)

  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeNodeBinding PopulateOnDemand Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeNodeBinding PopulateOnDemand Example</h3>
    
      <asp:TreeView id="BookTreeView" 
        DataSourceID="BookXmlDataSource"
        ExpandDepth="2"  
        runat="server">
         
        <DataBindings>
          <asp:TreeNodeBinding DataMember="Book" 
            TextField="Title"/>
          <asp:TreeNodeBinding DataMember="Chapter" 
            TextField="Heading"
            PopulateOnDemand="False"/>
          <asp:TreeNodeBinding DataMember="Section" 
            TextField="Heading"/>
        </DataBindings>
         
      </asp:TreeView>
      
      <asp:XmlDataSource id="BookXmlDataSource"  
        DataFile="Book.xml"
        runat="server">
      </asp:XmlDataSource>
    
    </form>
  </body>
</html>

次のコード例では、前のコード例のサンプル XML データを提供します。

<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>  

注釈

場合によっては、データ サイズやユーザー入力に依存するカスタム コンテンツのために、ツリー構造を静的に事前に定義することは実用的ではありません。 このため、コントロールは TreeView 動的ノードの作成をサポートしています。 プロパティが PopulateOnDemandtrue設定されている場合、オブジェクトが適用される TreeNodeBinding ノードの子ノードは、ノードが展開されるときに実行時に設定されます。

コントロールの を AutoGenerateDataBindingstrue設定してデータ バインディングをTreeView作成する場合、作成されるバインドのプロパティは PopulateOnDemandtrue設定されます。 宣言によって作成されるデータ バインディングには、 プロパティが PopulateOnDemandfalse設定されています。 宣言型構文を使用すると、個々のデータ バインディングの動作を制御できます。

注意

クラスの PopulateOnDemandTreeNode プロパティとは異なり、 PopulateOnDemand プロパティでは、 などのXmlDataSourceデータ ソース 管理を使用している場合、イベントに対TreeNodePopulateしてイベント処理メソッドを定義する必要はありません。 代わりに、コントロールは TreeView 、コレクション内のオブジェクトのプロパティを使用して、イベント処理メソッドを TreeNodeBinding 動的に DataBindings 生成します。 イベントのイベント処理メソッド TreeNodePopulate は引き続き定義できますが、コントロールのイベント処理メソッドの後に TreeView 呼び出されます。

サポートされているブラウザーでは、クライアント側ノードの作成を利用することもできます。 これを有効にすると、コントロールは TreeView 、そのノードが展開されたときにクライアント上でノードを動的に設定できるため、サーバーにポストバックする必要がなくなります。 クライアント側ノードの作成の詳細については、「」を参照してください PopulateNodesFromClient

このプロパティの値はビュー ステートに格納されます。

適用対象

こちらもご覧ください