DetailsViewDesigner.GetDesignTimeHtml Metoda

Definicja

Pobiera znaczniki używane do renderowania skojarzonej DetailsView kontrolki w czasie projektowania.

Przeciążenia

GetDesignTimeHtml()

Pobiera znaczniki używane do renderowania skojarzonej kontrolki w czasie projektowania.

GetDesignTimeHtml(DesignerRegionCollection)

Pobiera znaczniki używane do renderowania skojarzonej kontrolki w czasie projektowania i wypełnia kolekcję regionów projektanta.

GetDesignTimeHtml()

Pobiera znaczniki używane do renderowania skojarzonej kontrolki w czasie projektowania.

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

Zwraca

String

Znacznik String zawierający znaczniki używane do renderowania DetailsView w czasie projektowania.

Przykłady

Poniższy przykład kodu pokazuje, jak zastąpić GetDesignTimeHtml metodę w klasie dziedziczonej z DetailsViewDesigner klasy w celu zmiany wyglądu DetailsView kontrolki w czasie projektowania. Przykład dodaje nowy pierwszy wiersz do siatki, aby zawierał Caption właściwość , jeśli jest zdefiniowana Caption . BorderStyle Jeśli właściwość kontrolki, która jest pochodna, DetailsView jest wartością NotSet lubNone, rysuje niebieskie kreskowane obramowanie wokół kontrolki, GetDesignTimeHtml aby jego zakres był bardziej widoczny. Nie zmienia wyglądu kontrolki w czasie wykonywania.

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

Uwagi

GetDesignTimeHtml() Najpierw metoda ustawia AutoGenerateRows właściwość kontrolki DetailsView na true, jeśli kolekcja jest pustaFields. Następnie GetDesignTimeHtml ustawia DataKeyNames kolekcję GetDesignTimeHtml kontrolki na pustą String tablicę, jeśli nie można uzyskać schematu źródła danych. Odświeża obiekt, TypeDescriptor aby wymusić PreFilterProperties wywołanie metody. Następnie wywołuje metodę podstawową w celu wygenerowania znaczników.

Uwagi dotyczące dziedziczenia

Jeśli zastąpisz GetDesignTimeHtml() metodę, pamiętaj, aby wywołać metodę podstawową, ponieważ w końcu przez kilka poziomów przesłonięcia wywołuje DetailsView kontrolkę lub kopię kontrolki w celu wygenerowania znaczników.

Zobacz też

Dotyczy

GetDesignTimeHtml(DesignerRegionCollection)

Pobiera znaczniki używane do renderowania skojarzonej kontrolki w czasie projektowania i wypełnia kolekcję regionów projektanta.

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

Parametry

regions
DesignerRegionCollection

Element DesignerRegionCollection , do którego należy dodać definicje wybranych i możliwych do kliknięcia regionów w widoku czasu projektowania kontrolki.

Zwraca

String

Znacznik String zawierający znaczniki używane do renderowania DetailsView w czasie projektowania.

Przykłady

Poniższy przykład kodu pokazuje, jak zastąpić GetDesignTimeHtml metodę w klasie dziedziczonej DetailsViewDesigner z klasy w celu zmiany wyglądu DetailsView kontrolki w czasie projektowania. Przykład dodaje nowy pierwszy wiersz do siatki, aby zawierał Caption właściwość , jeśli jest zdefiniowana Caption . BorderStyle Jeśli właściwość kontrolki, która pochodzi z DetailsView wartości lubNone, NotSet rysuje niebieskie obramowanie kreskowane wokół kontrolki, GetDesignTimeHtml aby jego zakres był bardziej widoczny. Nie zmienia wyglądu kontrolki w czasie wykonywania.

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

Uwagi

Metoda DetailsViewDesigner.GetDesignTimeHtml wywołuje metodę DetailsViewDesigner.GetDesignTimeHtml , aby wygenerować znaczniki renderowania kontrolki DetailsView w czasie projektowania. Metoda DetailsViewDesigner.GetDesignTimeHtml jest regions również wypełniana obiektem DesignerRegion dla każdego możliwego do kliknięcia lub wybranego regionu renderowania w czasie projektowania.

DetailsViewW przypadku elementu pierwsza komórka w każdym wierszu można zaznaczyć. Wszystkie komórki w wierszach można kliknąć.

Uwagi dotyczące dziedziczenia

Jeśli zastąpisz GetDesignTimeHtml(DesignerRegionCollection) metodę, pamiętaj, aby wywołać metodę podstawową lub GetDesignTimeHtml() przeciążenie, ponieważ w końcu wywołaj kilka poziomów zastąpienia, wywołaj DetailsView kontrolkę lub kopię kontrolki, aby wygenerować znaczniki.

Zobacz też

Dotyczy