共用方式為


DataListDesigner.GetDesignTimeHtml 方法

定義

取得 HTML,用於在設計階段表示 DataList 控制項。

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

傳回

HTML,用於在設計階段表示 DataList 控制項。

範例

下列程式代碼範例示範如何覆寫 GetDesignTimeHtml 方法。 如果控件的 WebControl.Enabled 屬性為 true,它會改變設計介面上的控件外觀。

程式代碼會使用 Try...Catch...Finally 語法來執行下列動作:

  • Try 段會變更 控件屬性的值。

  • Catch 段會攔截任何例外狀況,並將其傳送至 GetErrorDesignTimeHtml 方法。

  • Finally 段會將屬性設定為其原始值。

此程式代碼範例是提供給 類別之較大範例的 DataListDesigner 一部分。

public override string GetDesignTimeHtml()
{
    string designTimeHtml = String.Empty;

    simpleGView = (SimpleGridView)Component;

    // Check the control's BorderStyle property to  
    // conditionally render design-time HTML.
    if (simpleGView.BorderStyle == BorderStyle.NotSet)
    {
        // Save the current property settings in variables.
        int oldCellPadding = simpleGView.CellPadding;
        Unit oldBorderWidth = simpleGView.BorderWidth;
        Color oldBorderColor = simpleGView.BorderColor;

        // Set properties and generate the design-time HTML.
        try
        {
            simpleGView.Caption = "SimpleGridView";
            simpleGView.CellPadding = 1;
            simpleGView.BorderWidth = Unit.Pixel(3);
            simpleGView.BorderColor = Color.Red;

            designTimeHtml = base.GetDesignTimeHtml();
        }
        catch (Exception ex)
        {
            // Get HTML from the GetErrorDesignTimeHtml 
            // method if an exception occurs.
            designTimeHtml = GetErrorDesignTimeHtml(ex);

            // Return the properties to their original values.
        }
        finally
        {
            simpleGView.CellPadding = oldCellPadding;
            simpleGView.BorderWidth = oldBorderWidth;
            simpleGView.BorderColor = oldBorderColor;
        }
    }
    else
    {
        designTimeHtml = base.GetDesignTimeHtml();
    }

    return designTimeHtml;
}

protected override string
    GetErrorDesignTimeHtml(System.Exception exc)
{
    return CreatePlaceHolderDesignTimeHtml(
        "ASPNET.Examples: An error occurred while rendering the GridView.");
}
Public Overrides Function GetDesignTimeHtml() As String
    Dim designTimeHtml As String = String.Empty

    simpleGView = CType(Component, SimpleGridView)

    ' Check the control's BorderStyle property to  
    ' conditionally render design-time HTML.
    If (simpleGView.BorderStyle = BorderStyle.NotSet) Then
        ' Save the current property settings in variables.
        Dim oldCellPadding As Integer = simpleGView.CellPadding
        Dim oldBorderWidth As Unit = simpleGView.BorderWidth
        Dim oldBorderColor As Color = simpleGView.BorderColor

        ' Set properties and generate the design-time HTML.
        Try
            simpleGView.Caption = "SimpleGridView"
            simpleGView.CellPadding = 1
            simpleGView.BorderWidth = Unit.Pixel(3)
            simpleGView.BorderColor = Color.Red

            designTimeHtml = MyBase.GetDesignTimeHtml()

        Catch ex As Exception
            ' Get HTML from the GetErrorDesignTimeHtml 
            ' method if an exception occurs.
            designTimeHtml = GetErrorDesignTimeHtml(ex)

            ' Return the properties to their original values.
        Finally
            simpleGView.CellPadding = oldCellPadding
            simpleGView.BorderWidth = oldBorderWidth
            simpleGView.BorderColor = oldBorderColor
        End Try

    Else
        designTimeHtml = MyBase.GetDesignTimeHtml()
    End If

    Return designTimeHtml
End Function

Protected Overrides Function _
    GetErrorDesignTimeHtml(ByVal exc As Exception) As String

    Return CreatePlaceHolderDesignTimeHtml( _
        "ASPNET.Examples: An error occurred while rendering the GridView.")

End Function

適用於

另請參閱