DetailsViewDesigner Class

Provides design-time support in a visual designer for the DetailsView control.

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

'Declaration
Public Class DetailsViewDesigner
	Inherits DataBoundControlDesigner
'Usage
Dim instance As DetailsViewDesigner

public class DetailsViewDesigner extends DataBoundControlDesigner
public class DetailsViewDesigner extends DataBoundControlDesigner
Not applicable.

In a visual designer, when you switch from Source to Design view, the markup source code that describes the DetailsView control is parsed and a design-time version of the control is created on the design surface. When you switch back to Source view, the design-time control is persisted to markup source code and edited into the markup for the Web page.

The properties of the DetailsViewDesigner class provide the following functionality:

  • The ActionLists property returns a DesignerActionListCollection object, which typically contains an object that is derived from the DesignerActionList class for each level in the inheritance tree of the designer.

  • The AutoFormats property returns a collection of formatting schemes for display in the Auto Format dialog box.

  • The TemplateGroups property returns a collection of template groups for the fields of the associated DetailsView control and the top level DetailsView templates.

  • The UsePreviewControl property always returns true, indicating that the designer creates a temporary copy of the associated DetailsView control to generate the design-time markup.

The DetailsViewDesigner class methods provide the following functionality:

  • The DataBind method binds the associated DetailsView control to a design-time data source.

  • The GetDesignTimeHtml method returns the markup that is used to render the associated DetailsView at design time.

  • The Initialize method prepares the designer to view, edit, and design the associated DetailsView.

  • The OnClick method is called when a region of the design-time view of the associated DetailsView is clicked.

  • The OnSchemaRefreshed method is called when the schema of the data source of the associated DetailsView changes.

  • The PreFilterProperties method is used to remove or add additional properties or to shadow properties of the associated DetailsView.

Design-time editable regions are not supported in the DetailsView control, so the GetEditableDesignerRegionContent and SetEditableDesignerRegionContent methods have no functionality.

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

The example derives the MyDetailsView control from the DetailsView. The MyDetailsView is simply a copy of the DetailsView control. The example also derives the MyDetailsViewDesigner class from DetailsViewDesigner and places a DesignerAttribute object for MyDetailsViewDesigner on the MyDetailsView control.

The MyDetailsViewDesigner overrides the SampleRowCount property to specify that the pager row of the design-time view of the MyDetailsView contain five page links. It overrides the PreFilterProperties method to make the NamingContainer property visible in the Property grid at design time. It overrides the GetDesignTimeHtml method to include the Caption property, if it is specified, as a new first row in the MyDetailsView grid at design time. If the BorderStyle property of the MyDetailsView is the NotSet or None value, the GetDesignTimeHtml draws a blue dashed border around the control to make its extent more visible.

Imports System
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 MyDetailsView is a copy of the DetailsView.
    <AspNetHostingPermission(SecurityAction.Demand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    <Designer(GetType(Examples.VB.WebControls.Design.MyDetailsViewDesigner))> _
    Public Class MyDetailsView
        Inherits DetailsView
    End Class ' MyVBDetailsView

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

        ' Determines the number of page links in the pager row
        ' when viewed in the designer.
        Protected Overrides ReadOnly Property SampleRowCount() As Integer
            Get
                ' Render five page links in the pager row.
                Return 5
            End Get
        End Property ' SampleRowCount

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

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

            ' Make the NamingContainer 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

        ' Generate the design-time markup.
        Private Const capTag As String = "caption"
        Private Const trOpen As String = "tr><td colspan=2 align=center"
        Private Const trClose As String = "td></tr"

        Public Overrides Function GetDesignTimeHtml() As String

            ' Make the full extent of the control more visible in the designer.
            ' If the border style is None or NotSet, change the border to
            ' a wide, blue, dashed line. Include the caption within the border.
            Dim myDV As MyDetailsView = CType(Component, MyDetailsView)
            Dim markup As String = Nothing
            Dim charX As Integer

            ' Check if the border style should be changed.
            If (myDV.BorderStyle = BorderStyle.NotSet Or _
                myDV.BorderStyle = BorderStyle.None) Then

                Dim oldBorderStyle As BorderStyle = myDV.BorderStyle
                Dim oldBorderWidth As Unit = myDV.BorderWidth
                Dim oldBorderColor As Color = myDV.BorderColor

                ' Set design-time properties and catch any exceptions.
                Try
                    myDV.BorderStyle = BorderStyle.Dashed
                    myDV.BorderWidth = Unit.Pixel(3)
                    myDV.BorderColor = Color.Blue

                    ' Call the base method to generate the markup.
                    markup = MyBase.GetDesignTimeHtml()

                Catch ex As Exception
                    markup = GetErrorDesignTimeHtml(ex)

                Finally
                    ' Restore the properties to their original settings.
                    myDV.BorderStyle = oldBorderStyle
                    myDV.BorderWidth = oldBorderWidth
                    myDV.BorderColor = oldBorderColor
                End Try

            Else
                ' Call the base method to generate the markup.
                markup = MyBase.GetDesignTimeHtml()
            End If

            ' Look for a <caption> tag.
            charX = markup.IndexOf(capTag)
            If charX > 0 Then

                ' Replace the first caption with 
                ' "tr><td colspan=2 align=center".
                markup = markup.Remove(charX, _
                    capTag.Length).Insert(charX, trOpen)

                ' Replace the second caption with "td></tr".
                charX = markup.IndexOf(capTag, charX)
                If charX > 0 Then
                    markup = markup.Remove(charX, _
                        capTag.Length).Insert(charX, trClose)
                End If
            End If

            Return markup

        End Function ' GetDesignTimeHtml
    End Class ' MyDetailsViewDesigner
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: