GridViewDesigner.GetDesignTimeHtml Méthode

Définition

Obtient le balisage utilisé pour restituer le contrôle GridView associé au moment de la conception.

Surcharges

GetDesignTimeHtml()

Obtient le balisage utilisé pour afficher le contrôle associé au moment de la conception.

GetDesignTimeHtml(DesignerRegionCollection)

Obtient le balisage utilisé pour afficher le contrôle associé au moment de la conception et remplit une collection de zones du concepteur.

GetDesignTimeHtml()

Obtient le balisage utilisé pour afficher le contrôle associé au moment de la conception.

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

Retours

String qui contient le balisage utilisé pour afficher GridView au moment de la conception.

Exemples

L’exemple de code suivant montre comment remplacer la GetDesignTimeHtml méthode dans une classe héritée de la GridViewDesigner classe pour modifier l’apparence du contrôle au moment du GridView design. L’exemple ajoute une nouvelle première ligne à la grille pour contenir la Caption propriété, si est Caption défini. Si la BorderStyle propriété du contrôle qui est dérivé de la classe a la GridViewNotSet valeur ou None , dessine GetDesignTimeHtml une bordure en pointillés bleus autour du contrôle pour rendre son étendue plus visible. Elle ne modifie pas l’apparence au moment de l’exécution du contrôle.

// 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.
    MyGridView myGV = (MyGridView)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
' 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 MyGridView = CType(Component, MyGridView)
    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

Remarques

La méthode GetDesignTimeHtml() effectue les opérations suivantes :

  1. Définit la AutoGenerateColumns propriété du contrôle sur true, si la Columns propriété est vide.

  2. Définit la DataKeyNames propriété du contrôle sur null, si le schéma de la source de données ne peut pas être obtenu.

  3. Actualise l’objet TypeDescriptor pour forcer l’appel de la PreFilterProperties méthode.

  4. Appelle la méthode de base pour générer le balisage.

Notes pour les héritiers

Si vous remplacez la GetDesignTimeHtml() méthode, veillez à appeler la méthode de base, car elle finit par passer par plusieurs niveaux de remplacement, appelle sur le GridView contrôle ou une copie du contrôle pour générer le balisage.

Voir aussi

S’applique à

GetDesignTimeHtml(DesignerRegionCollection)

Obtient le balisage utilisé pour afficher le contrôle associé au moment de la conception et remplit une collection de zones du concepteur.

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

Paramètres

regions
DesignerRegionCollection

DesignerRegionCollection auquel sont ajoutées des définitions des régions pouvant être sélectionnées et sur lesquelles cliquer dans la vue au moment de la conception du contrôle.

Retours

String qui contient le balisage utilisé pour afficher GridView au moment de la conception.

Exemples

L’exemple de code suivant montre comment remplacer la GetDesignTimeHtml méthode dans une classe héritée de la GridViewDesigner classe pour modifier l’apparence du contrôle au moment du GridView design. L’exemple ajoute une nouvelle première ligne à la grille pour contenir la Caption propriété, si est Caption défini. Si la BorderStyle propriété du contrôle qui est dérivé de la classe a la GridViewNotSet valeur ou None , dessine GetDesignTimeHtml une bordure en pointillés bleus autour du contrôle pour rendre son étendue plus visible. Elle ne modifie pas l’apparence au moment de l’exécution du contrôle.

// 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.
    MyGridView myGV = (MyGridView)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
' 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 MyGridView = CType(Component, MyGridView)
    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

Remarques

La GetDesignTimeHtml(DesignerRegionCollection) méthode appelle la GetDesignTimeHtml() méthode pour générer le balisage pour le rendu au moment du design du GridView contrôle. Le GetDesignTimeHtml(DesignerRegionCollection) remplit regions également avec un DesignerRegion objet pour chaque zone cliquable ou sélectionnable du rendu au moment du design.

Pour , GridViewla première cellule de chaque ligne est sélectionnable ; toutes les cellules des lignes sont cliquables.

Notes pour les héritiers

Si vous remplacez la GetDesignTimeHtml(DesignerRegionCollection) méthode, veillez à appeler la méthode de base ou la GetDesignTimeHtml() surcharge, car ils finissent par appeler sur le GridView contrôle ou une copie du contrôle pour générer le balisage via plusieurs niveaux de remplacement.

Voir aussi

S’applique à