Share via


GridViewDesigner.GetDesignTimeHtml Metoda

Definice

Získá kód, který se používá k vykreslení přidruženého GridView ovládacího prvku v době návrhu.

Přetížení

GetDesignTimeHtml()

Získá kód, který se používá k vykreslení přidruženého ovládacího prvku v době návrhu.

GetDesignTimeHtml(DesignerRegionCollection)

Získá kód, který se používá k vykreslení přidruženého ovládacího prvku v době návrhu a naplní kolekci oblastí návrháře.

GetDesignTimeHtml()

Získá kód, který se používá k vykreslení přidruženého ovládacího prvku v době návrhu.

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

Návraty

A String obsahující kód použitý k vykreslení v době návrhu GridView .

Příklady

Následující příklad kódu ukazuje, jak přepsat metodu GetDesignTimeHtml ve třídě, která je zděděna z GridViewDesigner třídy změnit vzhled ovládacího prvku v době návrhu GridView . Příklad přidá do mřížky nový první řádek, který bude obsahovat Caption vlastnost , pokud Caption je definována. BorderStyle Pokud vlastnost ovládacího prvku, který je odvozen od GridView třídy má NotSet hodnotu nebo None , GetDesignTimeHtml nakreslí modré přerušované ohraničení kolem ovládacího prvku, aby jeho rozsah byl více viditelný. Nemění vzhled ovládacího prvku za běhu.

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

Poznámky

Metoda GetDesignTimeHtml() provede následující:

  1. AutoGenerateColumns Nastaví vlastnost ovládacího prvku na true, pokud Columns je vlastnost prázdná.

  2. DataKeyNames Nastaví vlastnost ovládacího prvku na null, pokud nelze získat schéma zdroje dat.

  3. Aktualizuje objekt tak TypeDescriptor , aby vynutil PreFilterProperties zavolání metody.

  4. Zavolá základní metodu pro vygenerování kódu.

Poznámky pro dědice

Pokud přepíšete metodu GetDesignTimeHtml() , nezapomeňte volat základní metodu, protože nakonec prostřednictvím několika úrovní přepsání volá na GridView ovládací prvek nebo kopii ovládacího prvku, aby se vygeneroval kód.

Viz také

Platí pro

GetDesignTimeHtml(DesignerRegionCollection)

Získá kód, který se používá k vykreslení přidruženého ovládacího prvku v době návrhu a naplní kolekci oblastí návrháře.

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

A DesignerRegionCollection , do kterého jsou přidány definice oblastí, na které lze vybrat a na které lze kliknout, v zobrazení v době návrhu ovládacího prvku.

Návraty

A String obsahující kód použitý k vykreslení v době návrhu GridView .

Příklady

Následující příklad kódu ukazuje, jak přepsat metodu GetDesignTimeHtml ve třídě, která je zděděna z GridViewDesigner třídy změnit vzhled ovládacího prvku v době návrhu GridView . Příklad přidá do mřížky nový první řádek, který bude obsahovat Caption vlastnost , pokud Caption je definována. BorderStyle Pokud vlastnost ovládacího prvku, který je odvozen od GridView třídy má NotSet hodnotu nebo None , GetDesignTimeHtml nakreslí modré přerušované ohraničení kolem ovládacího prvku, aby jeho rozsah byl více viditelný. Nemění vzhled ovládacího prvku za běhu.

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

Poznámky

Metoda GetDesignTimeHtml(DesignerRegionCollection) volá metodu GetDesignTimeHtml() k vygenerování kódu pro vykreslování ovládacího prvku v době návrhu GridView . Objekt GetDesignTimeHtml(DesignerRegionCollection) se také naplní regions objektem DesignerRegion pro každou oblast, na které lze kliknout nebo vybrat při vykreslování v době návrhu.

GridViewPro je možné vybrat první buňku v každém řádku; na všechny buňky v řádcích lze kliknout.

Poznámky pro dědice

Pokud přepíšete metodu GetDesignTimeHtml(DesignerRegionCollection) , nezapomeňte volat základní metodu nebo GetDesignTimeHtml() přetížení, protože nakonec, přes několik úrovní přepsání, volání na GridView ovládací prvek nebo kopii ovládacího prvku, aby se vygeneroval kód.

Viz také

Platí pro