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

戻り値

デザイン時に DetailsView を表示するために使用するマークアップを格納している String

次のコード例は、 クラスからDetailsViewDesigner継承されたクラスのメソッドをオーバーライドGetDesignTimeHtmlして、デザイン時にコントロールの外観を変更する方法をDetailsView示しています。 この例では、 が定義されている場合は、 プロパティを含む新しい最初の Caption 行をグリッドに Caption 追加します。 BorderStyleからDetailsView派生したコントロールの プロパティが または None の値である場合、 はNotSetコントロール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()、コレクションがAutoGenerateRows空の場合、DetailsViewコントロールの プロパティを にtrueFields設定します。 次に、 DataKeyNamesGetDesignTimeHtml、データ ソースのスキーマを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

戻り値

デザイン時に DetailsView を表示するために使用するマークアップを格納している String

次のコード例は、 クラスからDetailsViewDesigner継承されたクラスの メソッドをオーバーライドGetDesignTimeHtmlして、デザイン時にコントロールの外観を変更する方法をDetailsView示しています。 この例では、 が定義されている場合は、 プロパティを含む新しい最初の Caption 行をグリッドに Caption 追加します。 BorderStyleからDetailsView派生したコントロールの プロパティが または None 値の場合、 はNotSetコントロール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、デザイン時レンダリングのDesignerRegionクリック可能または選択可能な領域ごとに オブジェクトを設定regionsします。

の場合、 DetailsView各行の最初のセルを選択できます。行内のすべてのセルはクリック可能です。

注意 (継承者)

メソッドをオーバーライドする GetDesignTimeHtml(DesignerRegionCollection) 場合は、基本メソッドまたは GetDesignTimeHtml() オーバーロードを必ず呼び出してください。これは、最終的には、いくつかのオーバーライド レベルを介して、コントロールまたはコントロールのコピーを DetailsView 呼び出してマークアップを生成するためです。

こちらもご覧ください

適用対象