HierarchicalDataBoundControl.PerformDataBinding Yöntem

Tanım

Türetilmiş bir sınıfta geçersiz kılındığında, veri kaynağındaki verileri denetime bağlar.

C#
protected internal virtual void PerformDataBinding();

Örnekler

Aşağıdaki kod örneği, yönteminin PerformDataBinding öğesinden HierarchicalDataBoundControltüretilen bir sınıfta nasıl uygulanduğunu gösterir. DenetimGeneologyTree, ilişkili HierarchicalDataSourceViewiçinden alınan ve IHierarchyData nesneleri arasında IHierarchicalEnumerable yinelenir ve bağlı olduğu veriler için bir metin ağacı yapısı oluşturur. Bu kod örneği, sınıfı için HierarchicalDataBoundControl sağlanan daha büyük bir örneğin parçasıdır.

C#
protected override void PerformDataBinding() {
    base.PerformDataBinding();

    // Do not attempt to bind data if there is no
    // data source set.
    if (!IsBoundUsingDataSourceID && (DataSource == null)) {
        return;
    }
    
    HierarchicalDataSourceView view = GetData(RootNode.DataPath);
    
    if (view == null) {
        throw new InvalidOperationException
            ("No view returned by data source control.");
    }                                  
    
    IHierarchicalEnumerable enumerable = view.Select();
    if (enumerable != null) {
                    
        Nodes.Clear();
                        
        try {
            RecurseDataBindInternal(RootNode, enumerable, 1);
        }
        finally {
        }
    }
}
private void RecurseDataBindInternal(TreeNode node, 
    IHierarchicalEnumerable enumerable, int depth) {                                    
                
    foreach(object item in enumerable) {
        IHierarchyData data = enumerable.GetHierarchyData(item);

        if (null != data) {
            // Create an object that represents the bound data
            // to the control.
            TreeNode newNode = new TreeNode();
            RootViewNode rvnode = new RootViewNode();
            
            rvnode.Node = newNode;
            rvnode.Depth = depth;

            // The dataItem is not just a string, but potentially
            // an XML node or some other container. 
            // If DataTextField is set, use it to determine which 
            // field to render. Otherwise, use the first field.                    
            if (DataTextField.Length > 0) {
                newNode.Text = DataBinder.GetPropertyValue
                    (data, DataTextField, null);
            }
            else {
                PropertyDescriptorCollection props = 
                    TypeDescriptor.GetProperties(data);

                // Set the "default" value of the node.
                newNode.Text = String.Empty;                        

                // Set the true data-bound value of the TextBox,
                // if possible.
                if (props.Count >= 1) {                        
                    if (null != props[0].GetValue(data)) {
                        newNode.Text = 
                            props[0].GetValue(data).ToString();
                    } 
                }
            }

            Nodes.Add(rvnode);                    
            
            if (data.HasChildren) {
                IHierarchicalEnumerable newEnumerable = 
                    data.GetChildren();
                if (newEnumerable != null) {                            
                    RecurseDataBindInternal(newNode, 
                        newEnumerable, depth+1 );
                }
            }
            
            if ( _maxDepth < depth) _maxDepth = depth;
        }
    }
}

Açıklamalar

sınıfından DataBind veriye bağlı bir denetim HierarchicalDataBoundControl türetdiğinizde yöntemi yerine bu yöntemi uygulayın. Denetiminizin veri bağlama mantığını içine PerformDataBinding yerleştirmek ve DataBound olaylarının DataBinding yanlış sırada tetiklenmesini engeller.

Temel HierarchicalDataBoundControl sınıf bu yöntem için belirli bir uygulama sağlamasa da, PerformDataBinding yöntemi tarafından PerformSelect herhangi bir kullanıcı arabirimi denetiminin değerlerini yöntemi tarafından alınan verilere bağlamak için çağrılır PerformSelect .

Ş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