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


GridViewDesigner.GetDesignTimeHtml Метод

Определение

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

Перегрузки

Имя Описание
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 разметку, используемую для отрисовки GridView во время разработки.

Примеры

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

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

Комментарии

Метод выполняет следующее GetDesignTimeHtml() :

  1. AutoGenerateColumns Задает для свойства элемента управления trueзначение , если Columns свойство пусто.

  2. DataKeyNames Задает свойство элемента управленияnull, если схема источника данных не может быть получена.

  3. TypeDescriptor Обновляет объект, чтобы PreFilterProperties принудительно вызвать метод.

  4. Вызывает базовый метод для создания разметки.

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

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

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

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

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 разметку, используемую для отрисовки GridView во время разработки.

Примеры

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

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

Комментарии

Метод GetDesignTimeHtml(DesignerRegionCollection) вызывает GetDesignTimeHtml() метод для создания разметки для отрисовки GridView элемента управления во время разработки. Кроме того, объект GetDesignTimeHtml(DesignerRegionCollection) заполняется DesignerRegionregions для каждого щелчка или выборки области отрисовки во время разработки.

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

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

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

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

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