Export (0) Print
Expand All

HierarchicalDataBoundControlDesigner Class

Note: This class is new in the .NET Framework version 2.0.

Provides design-time support in a designer host for the HierarchicalDataBoundControl control.

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

public class HierarchicalDataBoundControlDesigner : BaseDataBoundControlDesigner
public class HierarchicalDataBoundControlDesigner extends BaseDataBoundControlDesigner
public class HierarchicalDataBoundControlDesigner extends BaseDataBoundControlDesigner

In a designer host, when the user switches from Source to Design view, the markup source code that describes a control that is derived from the HierarchicalDataBoundControl abstract class is parsed and a design-time version of the control is created on the design surface. When the user switches back to Source view, the design-time control is persisted to markup source code and edited into the markup for the Web page. The HierarchicalDataBoundControlDesigner class provides design-time support for controls that are derived from the HierarchicalDataBoundControl in a designer host.

The HierarchicalDataBoundControlDesigner class properties provide the following functionality:

The HierarchicalDataBoundControlDesigner class methods provide the following functionality:

  • The ConnectToDataSource method performs the actions that are necessary to connect to the current data source.

  • The CreateDataSource method creates a new data source for the associated control.

  • The DataBind method binds the associated control that is derived from the HierarchicalDataBoundControl class to a design-time data source.

  • The DisconnectFromDataSource method performs the actions that are necessary to disconnect from the current data source.

  • The GetDesignTimeDataSource method gets a data source that can be used at design time for the associated control.

  • The GetSampleDataSource method constructs a sample data source that can be used at design time for the associated control.

  • The PreFilterProperties method is used to remove properties from or add additional properties to or to shadow properties of the associated control that is derived from the HierarchicalDataBoundControl class.

The following code example shows how to extend the HierarchicalDataBoundControlDesigner class to change the appearance of controls that are derived from the HierarchicalDataBoundControl control at design time.

The example derives the MyHierarchicalDataBoundControl class from the HierarchicalDataBoundControl. The MyHierarchicalDataBoundControl class is simply a copy of the HierarchicalDataBoundControl. The example also derives the MyHierarchicalDataBoundControlDesigner class from the HierarchicalDataBoundControlDesigner class and places a DesignerAttribute object for the MyHierarchicalDataBoundControlDesigner on the MyHierarchicalDataBoundControl class.

The MyHierarchicalDataBoundControlDesigner overrides the PreFilterProperties method to make the NamingContainer property visible in the Properties grid at design time. It overrides the GetDesignTimeHtml method to generate the markup for a placeholder if the design time markup is a null reference (Nothing in Visual Basic) or Empty, or if the design-time markup is an empty <span> block (that is, if there is no inner markup between the <span> and </span> tags).

using System;
using System.IO;
using System.Web;
using System.Drawing;
using System.Web.UI.WebControls;
using System.Web.UI.Design.WebControls;
using System.Collections;
using System.ComponentModel;
using System.Security.Permissions;

namespace Examples.CS.WebControls.Design
{
    // The MyHierarchicalDataBoundControl is a copy of the 
    // HierarchicalDataBoundControl.
    [AspNetHostingPermission(SecurityAction.Demand, 
        Level = AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, 
        Level = AspNetHostingPermissionLevel.Minimal)]
    [Designer(typeof(Examples.CS.WebControls.Design.
        MyHierarchicalDataBoundControlDesigner))]
    public class MyHierarchicalDataBoundControl : 
        HierarchicalDataBoundControl
    {
    } // MyHierarchicalDataBoundControl

    // Override members of the ierarchicalDataBoundControlDesigner.
    [ReflectionPermission(SecurityAction.Demand, Flags=ReflectionPermissionFlag.MemberAccess)]
    public class MyHierarchicalDataBoundControlDesigner : 
        HierarchicalDataBoundControlDesigner
    {
        const string bracketClose = ">";
        const string spanOpen = "<SPAN";
        const string spanClose = "</SPAN>";

        // Return the markup for a placeholder, if the inner markup is empty.
        // For brevity, the code that is used to detect embedded white_space 
        // in the tags is not shown.
        public override string GetDesignTimeHtml()
        {
            // Get the design-time markup from the base method.
            string markup = base.GetDesignTimeHtml();

            // If the markup is null or empty, return the markup 
            // for the placeholder.
            if(markup == null || markup == string.Empty)
                return GetEmptyDesignTimeHtml();

            // Make the markup uniform case so that the IndexOf will work.
            string MARKUP = markup.ToUpper();
            int charX;

            // Look for a <span ...> tag.
            if ((charX = MARKUP.IndexOf(spanOpen)) >= 0)
            {
                // Find closing bracket of span open tag.
                if ((charX = MARKUP.IndexOf(bracketClose, 
                        charX+spanOpen.Length)) >= 0)
                {
                    // If the inner markup of <span ...></span> is empty, 
                    // return the markup for a placeholder.
                    if (string.Compare(MARKUP, charX + 1, spanClose, 0, 
                                        spanClose.Length) == 0)

                        return GetEmptyDesignTimeHtml();
                }
            }
            // Return the original markup, if the inner markup is not empty.
            return markup;
        }

        // Shadow the control properties with design-time properties.
        protected override void PreFilterProperties(IDictionary properties)
        {
            string namingContainer = "NamingContainer";

            // Call the base method first.
            base.PreFilterProperties(properties);

            // Make the NamingContainery visible in the Properties grid.
            PropertyDescriptor selectProp =
                (PropertyDescriptor)properties[namingContainer];
            properties[namingContainer] =
                TypeDescriptor.CreateProperty(selectProp.ComponentType,
                    selectProp, BrowsableAttribute.Yes);
        } // PreFilterProperties
    } // MyHierarchicalDataBoundControlDesigner
} // Examples.CS.WebControls.Design

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0
Show:
© 2014 Microsoft