FormViewDesigner Class

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

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

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

public class FormViewDesigner extends DataBoundControlDesigner
public class FormViewDesigner extends DataBoundControlDesigner
Not applicable.

In a visual designer, when you switch from Source to Design view, the markup source code that describes the FormView 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 the markup source code and edited into the markup for the Web page.

The properties of the FormViewDesigner 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 templates of the associated FormView.

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

The FormViewDesigner class methods provide the following functionality:

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

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

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

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

The example derives the MyFormView control from the FormView control. The MyFormView is simply a copy of the FormView. The example also derives the MyFormViewDesigner class from the FormViewDesigner and places a DesignerAttribute object for the MyFormViewDesigner on the MyFormView control.

The MyFormViewDesigner overrides the following items:

  • The SampleRowCount property to specify that the pager row for the design-time view of the MyFormView contain four page links.

  • The GetDesignTimeHtml method to include the Caption property, if it is specified, as a new first row in the MyFormView grid at design time. If the BorderStyle property of the MyFormView 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 MyFormView is a copy of the FormView.
    <AspNetHostingPermission(SecurityAction.Demand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    <Designer(GetType(Examples.VB.WebControls.Design.MyFormViewDesigner))> _
    Public Class MyFormView
        Inherits FormView
    End Class ' MyFormView

    ' Override members of the FormViewDesigner.
    Public Class MyFormViewDesigner
        Inherits FormViewDesigner

        ' Determines the number of design-time links in the pager row.
        Protected Overrides ReadOnly Property SampleRowCount() As Integer
            Get
                ' Render four links in the pager row.
                Return 4
            End Get
        End Property ' SampleRowCount

        ' Generate the design-time markup.
        Private Const capTag As String = "caption"
        Private Const trOpen As String = "tr><td colspan=9 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 myGV As MyFormView = CType(Component, MyFormView)
            Dim markup As String = Nothing
            Dim charX As Integer

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

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

                ' Set the design-time properties and catch any exceptions.
                Try
                    myGV.BorderStyle = BorderStyle.Dashed
                    myGV.BorderWidth = Unit.Pixel(3)
                    myGV.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.
                    myGV.BorderStyle = oldBorderStyle
                    myGV.BorderWidth = oldBorderWidth
                    myGV.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=9 align=center".
                ' It is okay if the colspan exceeds the 
                ' number of columns in the table.
                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 ' MyFormViewDesigner
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: