Actualización: noviembre 2007
Proporciona compatibilidad en tiempo de diseño en un diseñador visual para el control FormView.
Espacio de nombres:
System.Web.UI.Design.WebControls
Ensamblado:
System.Design (en System.Design.dll)
Visual Basic (Declaración)
Public Class FormViewDesigner _
Inherits DataBoundControlDesigner
Dim instance As FormViewDesigner
public class FormViewDesigner : DataBoundControlDesigner
public ref class FormViewDesigner : public DataBoundControlDesigner
public class FormViewDesigner extends DataBoundControlDesigner
public class FormViewDesigner extends DataBoundControlDesigner
En un diseñador visual, cuando cambia de la vista Código fuente a la vista Diseño, se analiza el código fuente de marcado que describe el control FormView y se crea una versión del control en tiempo de diseño en la superficie de diseño. Cuando se cambia de nuevo a la vista Código fuente, el control en tiempo de diseño queda almacenado en el código de marcado, y cualquier cambio realizado en él queda reflejado en el marcado de la página Web.
Las propiedades de la clase FormViewDesigner proporcionan la siguiente funcionalidad:
La propiedad ActionLists devuelve un objeto DesignerActionListCollection, que normalmente contiene un objeto derivado de la clase DesignerActionList para cada uno de los niveles del árbol de herencia del diseñador.
La propiedad AutoFormats devuelve una colección de esquemas de formato que se mostrarán en el cuadro de diálogo Formato automático.
La propiedad TemplateGroups devuelve una colección de grupos de plantillas para las plantillas del FormView asociado.
La propiedad UsePreviewControl devuelve siempre true, lo que indica que el diseñador crea una copia temporal del control FormView asociado para generar el marcado en tiempo de diseño.
Los métodos de la clase FormViewDesigner proporcionan la funcionalidad siguiente:
En el siguiente ejemplo de código se muestra cómo se extiende la clase FormViewDesigner para cambiar la apariencia de los controles que se derivan del control FormView en tiempo de diseño.
En el ejemplo se deriva el control MyFormView del control FormView. MyFormView es simplemente una copia de FormView. El ejemplo también deriva la clase MyFormViewDesigner de FormViewDesigner y coloca un objeto DesignerAttribute para MyFormViewDesigner en el control MyFormView.
MyFormViewDesigner reemplaza los elementos siguientes:
La propiedad SampleRowCount, para especificar que la fila de paginación de la vista en tiempo de diseño de MyFormView contiene cuatro vínculos de página.
El método GetDesignTimeHtml, para incluir la propiedad Caption, si se especifica, como una nueva primera fila en la cuadrícula MyFormView en tiempo de diseño. Si la propiedad BorderStyle de MyFormView es el valor NotSet o None, GetDesignTimeHtml dibuja un borde de línea discontinua azul alrededor del control para hacer más visible su extensión.
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
using System;
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 MyFormView is a copy of the FormView.
[AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal)]
[Designer(typeof(Examples.CS.WebControls.Design.MyFormViewDesigner))]
public class MyFormView : FormView
{
} // MyFormView
// Override members of the FormViewDesigner.
public class MyFormViewDesigner : FormViewDesigner
{
// Determines the number of design-time links in the pager row.
protected override int SampleRowCount
{
get
{
// Render four links in the pager row.
return 4;
}
} // SampleRowCount
// Generate the design-time markup.
const string capTag = "caption";
const string trOpen = "tr><td colspan=9 align=center";
const string trClose = "td></tr";
public override string GetDesignTimeHtml()
{
// 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.
MyFormView myGV = (MyFormView)Component;
string markup = null;
int charX;
// Check if the border style should be changed.
if (myGV.BorderStyle == BorderStyle.NotSet ||
myGV.BorderStyle == BorderStyle.None)
{
BorderStyle oldBorderStyle = myGV.BorderStyle;
Unit oldBorderWidth = myGV.BorderWidth;
Color oldBorderColor = 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 = base.GetDesignTimeHtml();
}
catch (Exception ex)
{
markup = GetErrorDesignTimeHtml(ex);
}
finally
{
// Restore the properties to their original settings.
myGV.BorderStyle = oldBorderStyle;
myGV.BorderWidth = oldBorderWidth;
myGV.BorderColor = oldBorderColor;
}
}
else
// Call the base method to generate the markup.
markup = base.GetDesignTimeHtml();
// Look for a <caption> tag.
if ((charX = markup.IndexOf(capTag)) > 0)
{
// 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".
if ((charX = markup.IndexOf(capTag, charX)) > 0)
markup = markup.Remove(charX,
capTag.Length).Insert(charX, trClose);
}
return markup;
} // GetDesignTimeHtml
} // MyFormViewDesigner
} // Examples.CS.WebControls.Design
System..::.Object
System.ComponentModel.Design..::.ComponentDesigner
System.Web.UI.Design..::.HtmlControlDesigner
System.Web.UI.Design..::.ControlDesigner
System.Web.UI.Design.WebControls..::.BaseDataBoundControlDesigner
System.Web.UI.Design.WebControls..::.DataBoundControlDesigner
System.Web.UI.Design.WebControls..::.FormViewDesigner
Seguridad para subprocesos
Todos los miembros static (Shared en Visual Basic) públicos de este tipo son seguros para la ejecución de subprocesos. No se garantiza que los miembros de instancias sean seguros para la ejecución de subprocesos.
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.
.NET Framework
Compatible con: 3.5, 3.0, 2.0
Referencia
Otros recursos