Freigeben über


GridViewDesigner.GetDesignTimeHtml Methode

Definition

Ruft das Markup ab, das zum Rendern des zugeordneten GridView Steuerelements zur Entwurfszeit verwendet wird.

Überlädt

Name Beschreibung
GetDesignTimeHtml()

Ruft das Markup ab, das zum Rendern des zugeordneten Steuerelements zur Entwurfszeit verwendet wird.

GetDesignTimeHtml(DesignerRegionCollection)

Ruft das Markup ab, das zum Rendern des zugeordneten Steuerelements zur Entwurfszeit verwendet wird, und füllt eine Auflistung von Designerbereichen auf.

GetDesignTimeHtml()

Ruft das Markup ab, das zum Rendern des zugeordneten Steuerelements zur Entwurfszeit verwendet wird.

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

Gibt zurück

A String containing the markup used to render the GridView at design time.

Beispiele

Das folgende Codebeispiel zeigt, wie sie die GetDesignTimeHtml Methode in einer Klasse überschreiben, die von der GridViewDesigner Klasse geerbt wird, um die Darstellung des GridView Steuerelements zur Entwurfszeit zu ändern. Im Beispiel wird dem Raster eine neue erste Zeile hinzugefügt, die die Caption Eigenschaft enthält, falls dies Caption definiert ist. Wenn die BorderStyle Eigenschaft des Steuerelements, das von der GridView Klasse abgeleitet wird, über den oder None den NotSet Wert verfügt, zeichnet das GetDesignTimeHtml Steuerelement einen blauen gestrichelten Rahmen, um dessen Umfang sichtbarer zu machen. Die Laufzeitdarstellung des Steuerelements wird nicht geändert.

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

Hinweise

Die GetDesignTimeHtml() Methode führt folgende Aktionen aus:

  1. Legt die AutoGenerateColumns Eigenschaft des Steuerelements auf true, wenn die Columns Eigenschaft leer ist.

  2. Legt die DataKeyNames Eigenschaft des Steuerelements auf nullfest, wenn das Schema der Datenquelle nicht abgerufen werden kann.

  3. Aktualisiert das TypeDescriptor Objekt, um zu erzwingen, dass die PreFilterProperties Methode aufgerufen wird.

  4. Ruft die Basismethode auf, um das Markup zu generieren.

Hinweise für Vererber

Wenn Sie die GetDesignTimeHtml() Methode überschreiben, müssen Sie die Basismethode aufrufen, da sie schließlich über mehrere Überschreibungsebenen das GridView Steuerelement oder eine Kopie des Steuerelements aufruft, um das Markup zu generieren.

Weitere Informationen

Gilt für:

GetDesignTimeHtml(DesignerRegionCollection)

Ruft das Markup ab, das zum Rendern des zugeordneten Steuerelements zur Entwurfszeit verwendet wird, und füllt eine Auflistung von Designerbereichen auf.

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

Parameter

regions
DesignerRegionCollection

A DesignerRegionCollection to which definitions of the selectable and clickable regions in the design-time view of the control are added.

Gibt zurück

A String containing the markup used to render the GridView at design time.

Beispiele

Das folgende Codebeispiel zeigt, wie sie die GetDesignTimeHtml Methode in einer Klasse überschreiben, die von der GridViewDesigner Klasse geerbt wird, um die Darstellung des GridView Steuerelements zur Entwurfszeit zu ändern. Im Beispiel wird dem Raster eine neue erste Zeile hinzugefügt, die die Caption Eigenschaft enthält, falls dies Caption definiert ist. Wenn die BorderStyle Eigenschaft des Steuerelements, das von der GridView Klasse abgeleitet wird, über den oder None den NotSet Wert verfügt, zeichnet das GetDesignTimeHtml Steuerelement einen blauen gestrichelten Rahmen, um dessen Umfang sichtbarer zu machen. Die Laufzeitdarstellung des Steuerelements wird nicht geändert.

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

Hinweise

Die GetDesignTimeHtml(DesignerRegionCollection) Methode ruft die GetDesignTimeHtml() Methode auf, um das Markup für das Entwurfszeitrendering des GridView Steuerelements zu generieren. Außerdem GetDesignTimeHtml(DesignerRegionCollection) wird für jeden klickbaren oder auswählbaren Bereich des Entwurfszeitrenderings regions ein Objekt mit einem DesignerRegion Objekt aufgefüllt.

Für die GridViewZelle ist die erste Zelle in jeder Zeile auswählbar; alle Zellen in den Zeilen können geklickt werden.

Hinweise für Vererber

Wenn Sie die GetDesignTimeHtml(DesignerRegionCollection) Methode überschreiben, müssen Sie unbedingt die Basismethode oder die GetDesignTimeHtml() Überladung aufrufen, da sie schließlich über mehrere Überschreibungsebenen das GridView Steuerelement oder eine Kopie des Steuerelements aufrufen, um das Markup zu generieren.

Weitere Informationen

Gilt für: