共用方式為


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 的控制項屬性是 NotSetNone 值,則會 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() 如果集合是空的 DetailsView ,方法會將 AutoGenerateRows 控制項的 屬性設定為 trueFieldsGetDesignTimeHtml如果無法取得資料來源的架構,則會將 控制項的 GetDesignTimeHtml 集合設定 DataKeyNames 為空 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 的控制項屬性是 NotSetNone 值,則會 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.GetDesignTimeHtmlDetailsViewDesigner.GetDesignTimeHtml 呼叫 方法,以產生控制項設計階段轉譯的 DetailsView 標記。 方法 DetailsViewDesigner.GetDesignTimeHtml 也會針對設計階段轉譯的每個可點選或可選取區域填入 regionsDesignerRegion 物件。

DetailsView針對 ,每個資料列的第一個儲存格是可選取的;資料列中的所有儲存格都可以按一下。

給繼承者的注意事項

如果您覆寫 GetDesignTimeHtml(DesignerRegionCollection) 方法,請務必呼叫基底方法或 GetDesignTimeHtml() 多載,因為它們最終會透過數個覆寫層級呼叫控制項 DetailsView 或控制項複本來產生標記。

另請參閱

適用於