GridViewDesigner.GetDesignTimeHtml Metodo

Definizione

Ottiene il markup usato per il rendering del controllo GridView associato in fase di progettazione.

Overload

GetDesignTimeHtml()

Ottiene il markup usato per il rendering del controllo associato in fase di progettazione.

GetDesignTimeHtml(DesignerRegionCollection)

Ottiene il markup usato per eseguire il rendering del controllo associato in fase di progettazione e popola una raccolta di aree della finestra di progettazione.

GetDesignTimeHtml()

Ottiene il markup usato per il rendering del controllo associato in fase di progettazione.

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

Restituisce

Oggetto String contenente il markup usato per eseguire il rendering dell'oggetto GridView in fase di progettazione.

Esempio

Nell'esempio di codice seguente viene illustrato come eseguire l'override del GetDesignTimeHtml metodo in una classe ereditata dalla GridViewDesigner classe per modificare l'aspetto del GridView controllo in fase di progettazione. Nell'esempio viene aggiunta una nuova riga alla griglia per contenere la Caption proprietà , se Caption è definita. Se la BorderStyle proprietà del controllo derivato dalla GridView classe ha il NotSet valore o None , disegna GetDesignTimeHtml un bordo tratteggiato blu intorno al controllo per renderlo più visibile. Non modifica l'aspetto in fase di esecuzione del controllo.

// 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

Commenti

Il metodo GetDesignTimeHtml() esegue le operazioni seguenti:

  1. Imposta la AutoGenerateColumns proprietà del controllo su true, se la Columns proprietà è vuota.

  2. Imposta la DataKeyNames proprietà del controllo su null, se non è possibile ottenere lo schema dell'origine dati.

  3. Aggiorna l'oggetto TypeDescriptor per forzare la chiamata del PreFilterProperties metodo.

  4. Chiama il metodo di base per generare il markup.

Note per gli eredi

Se si esegue l'override del GetDesignTimeHtml() metodo , assicurarsi di chiamare il metodo di base, perché alla fine, tramite diversi livelli di override, chiama sul GridView controllo o una copia del controllo per generare il markup.

Vedi anche

Si applica a

GetDesignTimeHtml(DesignerRegionCollection)

Ottiene il markup usato per eseguire il rendering del controllo associato in fase di progettazione e popola una raccolta di aree della finestra di progettazione.

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

Parametri

regions
DesignerRegionCollection

Insieme DesignerRegionCollection al quale sono aggiunte definizioni delle aree selezionabili e selezionabili tramite clic nella visualizzazione Design-Time del controllo.

Restituisce

Oggetto String contenente il markup usato per eseguire il rendering dell'oggetto GridView in fase di progettazione.

Esempio

Nell'esempio di codice seguente viene illustrato come eseguire l'override del GetDesignTimeHtml metodo in una classe ereditata dalla GridViewDesigner classe per modificare l'aspetto del GridView controllo in fase di progettazione. Nell'esempio viene aggiunta una nuova riga alla griglia per contenere la Caption proprietà , se Caption è definita. Se la BorderStyle proprietà del controllo derivato dalla GridView classe ha il NotSet valore o None , disegna GetDesignTimeHtml un bordo tratteggiato blu intorno al controllo per renderlo più visibile. Non modifica l'aspetto in fase di esecuzione del controllo.

// 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

Commenti

Il GetDesignTimeHtml(DesignerRegionCollection) metodo chiama il GetDesignTimeHtml() metodo per generare il markup per il rendering in fase di progettazione del GridView controllo. Popola GetDesignTimeHtml(DesignerRegionCollection)regions inoltre con un DesignerRegion oggetto per ogni area selezionabile o selezionabile del rendering in fase di progettazione.

GridViewPer , la prima cella di ogni riga è selezionabile. Tutte le celle nelle righe sono selezionabili.

Note per gli eredi

Se si esegue l'override del GetDesignTimeHtml(DesignerRegionCollection) metodo, assicurarsi di chiamare il metodo di base o l'overload GetDesignTimeHtml() , perché alla fine, tramite diversi livelli di override, chiamare sul GridView controllo o una copia del controllo per generare il markup.

Vedi anche

Si applica a