Поделиться через


DetailsViewDesigner.GetDesignTimeHtml Метод

Определение

Возвращает разметку, используемую для отрисовки связанного элемента управления DetailsView во время разработки.

Перегрузки

GetDesignTimeHtml()

Получает разметку, используемую для отрисовки связанного элемента управления во время разработки.

GetDesignTimeHtml(DesignerRegionCollection)

Получает разметку, используемую для отрисовки связанного элемента управления во время разработки, а также заполняет коллекцию областей конструктора.

GetDesignTimeHtml()

Получает разметку, используемую для отрисовки связанного элемента управления во время разработки.

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

Возвращаемое значение

Объект типа String, содержащий разметку, которая используется для отрисовки объекта DetailsView во время разработки.

Примеры

В следующем примере кода показано, как переопределить GetDesignTimeHtml метод в классе, наследуемом от DetailsViewDesigner класса , чтобы изменить внешний вид элемента управления во время разработки DetailsView . В примере в сетку добавляется новая первая строка, содержащая Caption свойство , если Caption определен . BorderStyle Если свойство элемента управления, производного от DetailsView , является значением NotSet или None , GetDesignTimeHtml объект рисует синюю пунктирную границу вокруг элемента управления, чтобы сделать его экстент более видимым. Он не изменяет внешний вид элемента управления во время выполнения.

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

Комментарии

Во-первыхGetDesignTimeHtml(), метод задает свойству DetailsViewAutoGenerateRows элемента управления значение true, если Fields коллекция пуста. GetDesignTimeHtml Затем задает DataKeyNames для коллекции GetDesignTimeHtml элемента управления пустой String массив, если не удается получить схему источника данных. Объект обновляется для TypeDescriptor принудительного PreFilterProperties вызова метода. Затем он вызывает базовый метод для создания разметки.

Примечания для тех, кто наследует этот метод

При переопределении GetDesignTimeHtml() метода обязательно вызовите базовый метод, так как он в конечном итоге через несколько уровней переопределения вызывает DetailsView элемент управления или копию элемента управления для создания разметки.

См. также раздел

Применяется к

GetDesignTimeHtml(DesignerRegionCollection)

Получает разметку, используемую для отрисовки связанного элемента управления во время разработки, а также заполняет коллекцию областей конструктора.

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

Параметры

regions
DesignerRegionCollection

Объект DesignerRegionCollection, к которому должны быть добавлены определения областей с возможностью выбора или щелчка в представлении времени разработки для элемента управления.

Возвращаемое значение

Объект типа String, содержащий разметку, которая используется для отрисовки объекта DetailsView во время разработки.

Примеры

В следующем примере кода показано, как переопределить GetDesignTimeHtml метод в классе, наследуемом DetailsViewDesigner от класса , чтобы изменить внешний вид элемента управления во время разработки DetailsView . В примере в сетку добавляется новая первая строка, содержащая Caption свойство , если Caption определен . Если свойством BorderStyle элемента управления, производного от DetailsView , является NotSet значение или None , GetDesignTimeHtml объект рисует синюю пунктирную границу вокруг элемента управления, чтобы сделать его экстент более видимым. Он не изменяет внешний вид элемента управления во время выполнения.

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

Комментарии

Метод DetailsViewDesigner.GetDesignTimeHtml вызывает DetailsViewDesigner.GetDesignTimeHtml метод для создания разметки для отрисовки элемента управления во время разработки DetailsView . Метод DetailsViewDesigner.GetDesignTimeHtml также заполняет regions объектом для каждой DesignerRegion области с возможностью щелчка или выбора рендеринга во время разработки.

DetailsViewДля первой ячейки в каждой строке можно выбрать; все ячейки в строках доступны для щелчка.

Примечания для тех, кто наследует этот метод

При переопределении GetDesignTimeHtml(DesignerRegionCollection) метода обязательно вызовите базовый метод или перегрузку GetDesignTimeHtml() , так как они в конечном итоге через несколько уровней переопределения вызывают DetailsView элемент управления или копию элемента управления для создания разметки.

См. также раздел

Применяется к