Export (0) Print
Expand All

HierarchicalDataBoundControlDesigner Class

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)

'Declaration
Public Class HierarchicalDataBoundControlDesigner
	Inherits BaseDataBoundControlDesigner
'Usage
Dim instance As HierarchicalDataBoundControlDesigner

public class HierarchicalDataBoundControlDesigner extends BaseDataBoundControlDesigner
public class HierarchicalDataBoundControlDesigner extends BaseDataBoundControlDesigner
Not applicable.

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

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

Namespace Examples.VB.WebControls.Design

    ' The MyHierarchicalDataBoundControl is a copy of the 
    ' HierarchicalDataBoundControl.
    <AspNetHostingPermission(SecurityAction.Demand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    <Designer(GetType(Examples.VB.WebControls.Design. _
        MyHierarchicalDataBoundControlDesigner))> _
    Public Class MyHierarchicalDataBoundControl
        Inherits HierarchicalDataBoundControl
    End Class ' MyHierarchicalDataBoundControl

    ' Override members of the HierarchicalDataBoundControlDesigner.
    <ReflectionPermission(SecurityAction.Demand, Flags:=ReflectionPermissionFlag.MemberAccess)> _
    Public Class MyHierarchicalDataBoundControlDesigner
        Inherits HierarchicalDataBoundControlDesigner

        Private Const bracketClose As String = ">"
        Private Const spanOpen As String = "<SPAN"
        Private Const spanClose As String = "</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 Overrides Function GetDesignTimeHtml() As String

            ' Get the design-time markup from the base method.
            Dim markup As String = MyBase.GetDesignTimeHtml()

            ' If the markup is null or empty, return the markup 
            ' for the placeholder.
            If markup Is Nothing OrElse markup = String.Empty Then
                Return GetEmptyDesignTimeHtml()
            End If

            ' Make the markup uniform case so that the IndexOf will work.
            Dim markupUC As String = markup.ToUpper()
            Dim charX As Integer

            ' Look for a <span ...> tag.
            charX = markupUC.IndexOf(spanOpen)
            If charX >= 0 Then

                ' Find closing bracket of span open tag.
                charX = markupUC.IndexOf(bracketClose, charX + spanOpen.Length)
                If charX >= 0 Then

                    ' If the inner markup of <span ...></span> is empty, 
                    ' return the markup for a placeholder.
                    If String.Compare(markupUC, charX + 1, _
                        spanClose, 0, spanClose.Length) = 0 Then

                        Return GetEmptyDesignTimeHtml()
                    End If
                End If
            End If

            ' Return the original markup, if the inner markup is not empty.
            Return markup
        End Function ' GetDesignTimeHtml

        ' Shadow the control properties with design-time properties.
        Protected Overrides Sub PreFilterProperties( _
            ByVal properties As IDictionary)

            Dim namingContainer As String = "NamingContainer"

            ' Call the base method first.
            MyBase.PreFilterProperties(properties)

            ' Make the NamingContainery visible in the Properties grid.
            Dim selectProp As PropertyDescriptor = _
                CType(properties(namingContainer), PropertyDescriptor)
            properties(namingContainer) = _
                TypeDescriptor.CreateProperty(selectProp.ComponentType, _
                    selectProp, BrowsableAttribute.Yes)
        End Sub ' PreFilterProperties
    End Class ' MyHierarchicalDataBoundControlDesigner
End Namespace ' Examples.VB.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 Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2015 Microsoft