TreeView.PopulateNodesFromClient Özellik

Tanım

düğüm verilerinin istemciden isteğe bağlı olarak doldurulup doldurulmadığını belirten bir değer alır veya ayarlar.

C#
public bool PopulateNodesFromClient { get; set; }

Özellik Değeri

true ağaç düğümü verilerini istemciden isteğe bağlı olarak doldurmak için; aksi takdirde , false. Varsayılan değer: true.

Örnekler

Aşağıdaki kod örneği, denetimdeki PopulateNodesFromClient düğümlerin TreeView istemci tarafı popülasyonunu etkinleştirmek için özelliğinin nasıl kullanılacağını gösterir. İstemci tarafı düğüm popülasyonu etkinleştirildiğinde, düğümlerin sunucuya geri göndermeye gerek kalmadan istemcide dinamik olarak doldurulduğunu göreceksiniz.

ASP.NET (C#)

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

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

  void PopulateNode(Object sender, TreeNodeEventArgs e)
  {

    // Call the appropriate method to populate a node at a particular level.
    switch(e.Node.Depth)
    {
      case 0:
        // Populate the first-level nodes.
        PopulateCategories(e.Node);
        break;
      case 1:
        // Populate the second-level nodes.
        PopulateProducts(e.Node);
        break;
      default:
        // Do nothing.
        break;
    }
    
  }

  void PopulateCategories(TreeNode node)
  {
    
    // Query for the product categories. These are the values
    // for the second-level nodes.
    DataSet ResultSet = RunQuery("Select CategoryID, CategoryName From Categories");

    // Create the second-level nodes.
    if(ResultSet.Tables.Count > 0)
    {
    
      // Iterate through and create a new node for each row in the query results.
      // Notice that the query results are stored in the table of the DataSet.
      foreach (DataRow row in ResultSet.Tables[0].Rows)
      {
        
        // Create the new node. Notice that the CategoryId is stored in the Value property 
        // of the node. This will make querying for items in a specific category easier when
        // the third-level nodes are created. 
        TreeNode newNode = new TreeNode();
        newNode.Text = row["CategoryName"].ToString(); 
        newNode.Value = row["CategoryID"].ToString();        

        // Set the PopulateOnDemand property to true so that the child nodes can be 
        // dynamically populated.
        newNode.PopulateOnDemand = true;
        
        // Set additional properties for the node.
        newNode.SelectAction = TreeNodeSelectAction.Expand;
        
        // Add the new node to the ChildNodes collection of the parent node.
        node.ChildNodes.Add(newNode);
        
      }
      
    }
    
  }

  void PopulateProducts(TreeNode node)
  {

    // Query for the products of the current category. These are the values
    // for the third-level nodes.
    DataSet ResultSet = RunQuery("Select ProductName From Products Where CategoryID=" + node.Value);

    // Create the third-level nodes.
    if(ResultSet.Tables.Count > 0)
    {
    
      // Iterate through and create a new node for each row in the query results.
      // Notice that the query results are stored in the table of the DataSet.
      foreach (DataRow row in ResultSet.Tables[0].Rows)
      {
      
        // Create the new node.
        TreeNode NewNode = new TreeNode(row["ProductName"].ToString());
        
        // Set the PopulateOnDemand property to false, because these are leaf nodes and
        // do not need to be populated.
        NewNode.PopulateOnDemand = false;
        
        // Set additional properties for the node.
        NewNode.SelectAction = TreeNodeSelectAction.None;
        
        // Add the new node to the ChildNodes collection of the parent node.
        node.ChildNodes.Add(NewNode);
        
      }
      
    }

  }

  DataSet RunQuery(String QueryString)
  {

    // Declare the connection string. This example uses Microsoft SQL Server 
    // and connects to the Northwind sample database.
    String ConnectionString = "server=localhost;database=NorthWind;Integrated Security=SSPI"; 

    SqlConnection DBConnection = new SqlConnection(ConnectionString);
    SqlDataAdapter DBAdapter;
    DataSet ResultsDataSet = new DataSet();

    try
    {

      // Run the query and create a DataSet.
      DBAdapter = new SqlDataAdapter(QueryString, DBConnection);
      DBAdapter.Fill(ResultsDataSet);

      // Close the database connection.
      DBConnection.Close();

    }
    catch(Exception ex)
    {

      // Close the database connection if it is still open.
      if(DBConnection.State == ConnectionState.Open)
      {
        DBConnection.Close();
      }
      
      Message.Text = "Unable to connect to the database.";

    }

    return ResultsDataSet;

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeView PopulateNodesFromClient Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView PopulateNodesFromClient Example</h3>
    
      <asp:TreeView id="LinksTreeView"
        Font-Names= "Arial"
        ForeColor="Blue"
        EnableClientScript="true"
        PopulateNodesFromClient="true"  
        OnTreeNodePopulate="PopulateNode"
        runat="server">
         
        <Nodes>
        
          <asp:TreeNode Text="Inventory" 
            SelectAction="Expand"  
            PopulateOnDemand="true"/>
        
        </Nodes>
        
      </asp:TreeView>
      
      <br /><br />
      
      <asp:Label id="Message" runat="server"/>

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

Açıklamalar

Bazen, veri boyutu veya kullanıcı girişine bağlı özel içerik nedeniyle ağaç yapısını statik olarak önceden tanımlı yapmak pratik olmaz. Bu nedenle denetim dinamik TreeView düğüm popülasyonunu destekler. Bir düğümün PopulateOnDemand özelliği olarak trueayarlandığında, düğüm genişletildiğinde bu düğüm çalışma zamanında doldurulur.

İsteğe bağlı düğümleri doldurmaya ek olarak, düğümleri doğrudan desteklenen bir istemci tarayıcısında doldurmak da mümkündür. PopulateNodesFromClient özelliği olarak trueayarlandığında, ağaç düğümlerini doldurmak için istemciden bir hizmet çağrılır ve bu da sunucuya geri gönderme gereksinimini ortadan kaldırır. Aksi takdirde, TreeView denetim düğümleri doldurmak için sunucuya geri gönderir.

Not

Özelliğin EnableClientScript olarak ayarlanması true için PopulateNodesFromClient özelliği de olarak ayarlanmalıdır true.

İstemcideki bir düğümü doldurmak için önce özelliğini true olarak ayarlayın PopulateNodesFromClient ve ardından düğümün PopulateOnDemand özelliğini olarak trueayarlayın. Ardından, düğümü program aracılığıyla dolduran olay için TreeNodePopulate bir olay işleme yöntemi tanımlayın. Tipik bir olay işleme yöntemi bir veri kaynağından düğüm verilerini alır, verileri bir düğüm yapısına yerleştirir ve ardından düğüm yapısını doldurulan düğümün koleksiyonuna ChildNodes ekler. Bir üst düğüm koleksiyonuna ChildNodes nesneler ekleyerek TreeNode bir düğüm yapısı oluşturursunuz.

Not

Bir düğümün PopulateOnDemand özelliği olarak trueayarlandığında, düğümün dinamik olarak doldurulması gerekir. Altta başka bir düğümü bildirimli olarak iç içe yerleştiremezsiniz; aksi takdirde, sayfada bir hata oluşur.

Not

İstemci tarafı düğüm popülasyonu özelliği, geri çağırma betiklerini destekleyen tarayıcılarda desteklenir. Tarayıcının geri çağırma betikleri erişimini destekleyip desteklemediğini denetlemek için sınıfının özelliğini HttpBrowserCapabilities kullanınSupportsCallback. Sınıfın HttpBrowserCapabilities özelliği aracılığıyla geçerli istek için sınıfının örneğine BrowserHttpRequest erişebilirsiniz.

Bu özelliğin değeri görünüm durumunda depolanır.

Şunlara uygulanır

Ürün Sürümler
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Ayrıca bkz.