Share via


DetailsViewDesigner.GetDesignTimeHtml Método

Definición

Obtiene el marcado que se utiliza para representar el control DetailsView asociado en tiempo de diseño.

Sobrecargas

GetDesignTimeHtml()

Obtiene el marcado que se usa para representar el control asociado en tiempo de diseño.

GetDesignTimeHtml(DesignerRegionCollection)

Obtiene el marcado que se utiliza para presentar el control asociado en tiempo de diseño y rellena una colección de regiones del diseñador.

GetDesignTimeHtml()

Obtiene el marcado que se usa para representar el control asociado en tiempo de diseño.

public:
 override System::String ^ GetDesignTimeHtml();
public override string GetDesignTimeHtml ();
override this.GetDesignTimeHtml : unit -> string
Public Overrides Function GetDesignTimeHtml () As String

Devoluciones

Un objeto String que contiene el marcado usado para representar DetailsView en tiempo de diseño.

Ejemplos

En el ejemplo de código siguiente se muestra cómo invalidar el GetDesignTimeHtml método en una clase heredada de la DetailsViewDesigner clase para cambiar la apariencia del DetailsView control en tiempo de diseño. En el ejemplo se agrega una nueva primera fila a la cuadrícula para que contenga la Caption propiedad , si Caption se define . Si la BorderStyle propiedad del control que se deriva de DetailsView es el NotSet valor o None , GetDesignTimeHtml dibuja un borde discontinuo azul alrededor del control para que su extensión sea más visible. No cambia la apariencia en tiempo de ejecución del control.

// Generate the design-time markup.
const string capTag = "caption";
const string trOpen = "tr><td colspan=2 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.
    MyDetailsView myDV = (MyDetailsView)Component;
    string markup = null;
    int charX;

    // Check if the border style should be changed.
    if (myDV.BorderStyle == BorderStyle.NotSet ||
        myDV.BorderStyle == BorderStyle.None)
    {
        BorderStyle oldBorderStyle = myDV.BorderStyle;
        Unit oldBorderWidth = myDV.BorderWidth;
        Color oldBorderColor = 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 = base.GetDesignTimeHtml();
        }
        catch (Exception ex)
        {
            markup = GetErrorDesignTimeHtml(ex);
        }
        finally
        {
            // Restore the properties to their original settings.
            myDV.BorderStyle = oldBorderStyle;
            myDV.BorderWidth = oldBorderWidth;
            myDV.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=2 align=center".
        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
' 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

Comentarios

En primer lugar, el GetDesignTimeHtml() método establece la AutoGenerateRows propiedad del DetailsView control trueen , si la Fields colección está vacía. A GetDesignTimeHtml continuación, establece la DataKeyNames colección del GetDesignTimeHtml control en una matriz vacía String si no se puede obtener el esquema del origen de datos. Actualiza el TypeDescriptor objeto para forzar la llamada al PreFilterProperties método. A continuación, llama al método base para generar el marcado.

Notas a los desarrolladores de herederos

Si invalida el GetDesignTimeHtml() método , asegúrese de llamar al método base porque finalmente, a través de varios niveles de invalidación, llama al DetailsView control o a una copia del control para generar el marcado.

Consulte también

Se aplica a

GetDesignTimeHtml(DesignerRegionCollection)

Obtiene el marcado que se utiliza para presentar el control asociado en tiempo de diseño y rellena una colección de regiones del diseñador.

public:
 override System::String ^ GetDesignTimeHtml(System::Web::UI::Design::DesignerRegionCollection ^ regions);
public override string GetDesignTimeHtml (System.Web.UI.Design.DesignerRegionCollection regions);
override this.GetDesignTimeHtml : System.Web.UI.Design.DesignerRegionCollection -> string
Public Overrides Function GetDesignTimeHtml (regions As DesignerRegionCollection) As String

Parámetros

regions
DesignerRegionCollection

Un objeto DesignerRegionCollection al que se agregarán definiciones de las regiones seleccionables y sobre las que se puede hacer clic en la vista en tiempo de diseño del control.

Devoluciones

Un objeto String que contiene el marcado usado para representar DetailsView en tiempo de diseño.

Ejemplos

En el ejemplo de código siguiente se muestra cómo invalidar el GetDesignTimeHtml método en una clase que se hereda de la DetailsViewDesigner clase para cambiar la apariencia del DetailsView control en tiempo de diseño. En el ejemplo se agrega una nueva primera fila a la cuadrícula para que contenga la Caption propiedad , si Caption se define . Si la BorderStyle propiedad del control que se deriva de DetailsView es el NotSet valor o None , GetDesignTimeHtml dibuja un borde discontinuo azul alrededor del control para que su extensión sea más visible. No cambia la apariencia en tiempo de ejecución del control.

// Generate the design-time markup.
const string capTag = "caption";
const string trOpen = "tr><td colspan=2 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.
    MyDetailsView myDV = (MyDetailsView)Component;
    string markup = null;
    int charX;

    // Check if the border style should be changed.
    if (myDV.BorderStyle == BorderStyle.NotSet ||
        myDV.BorderStyle == BorderStyle.None)
    {
        BorderStyle oldBorderStyle = myDV.BorderStyle;
        Unit oldBorderWidth = myDV.BorderWidth;
        Color oldBorderColor = 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 = base.GetDesignTimeHtml();
        }
        catch (Exception ex)
        {
            markup = GetErrorDesignTimeHtml(ex);
        }
        finally
        {
            // Restore the properties to their original settings.
            myDV.BorderStyle = oldBorderStyle;
            myDV.BorderWidth = oldBorderWidth;
            myDV.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=2 align=center".
        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
' 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

Comentarios

El DetailsViewDesigner.GetDesignTimeHtml método llama al DetailsViewDesigner.GetDesignTimeHtml método para generar el marcado para la representación en tiempo de diseño del DetailsView control. El DetailsViewDesigner.GetDesignTimeHtml método también se regions rellena con un DesignerRegion objeto para cada región seleccionable o seleccionable de la representación en tiempo de diseño.

DetailsViewPara , se puede seleccionar la primera celda de cada fila; se pueden hacer clic en todas las celdas de las filas.

Notas a los desarrolladores de herederos

Si invalida el GetDesignTimeHtml(DesignerRegionCollection) método , asegúrese de llamar al método base o a la GetDesignTimeHtml() sobrecarga porque finalmente, a través de varios niveles de invalidación, llame a en el DetailsView control o una copia del control para generar el marcado.

Consulte también

Se aplica a