次の方法で共有


TableDesigner.GetDesignTimeHtml メソッド

デザイン時にコントロールを表すために使用する HTML を取得します。

Overrides Public Function GetDesignTimeHtml() As String
[C#]
public override string GetDesignTimeHtml();
[C++]
public: String* GetDesignTimeHtml();
[JScript]
public override function GetDesignTimeHtml() : String;

戻り値

デザイン時にコントロールを表すために使用する HTML。

解説

このメソッドによって、テーブルに少なくとも 1 つの行と 1 つのセルが存在するようになり、また、デザイン時に表示されるテキストがこのセルに格納されるようになります。

使用例

[Visual Basic] GetDesignTimeHtml メソッドをオーバーライドして、デザイン画面で StyledTable クラスに行とセルを表示するコード例を次に示します。このコードは、 Try ブロックで、表の中に行またはセルが含まれているかどうかをチェックし、含まれていない場合は、行を作成し、ループを使用してその行に対して 2 つのセルを作成します。併せて、デザイン時に各セルに表示するプレースホルダ テキストを作成します。表は空でなく、行が空の場合は、同じループを使用して、セルを作成し、セルに値を設定します。最後に Finally ブロックで、設定した値を元に戻します。

 
' Override the GetDesignTimeHtml method to display
' placeholder text at design time for the 
' rows and cells of the StyledTable class.
Public Overrides Function GetDesignTimeHtml() As String
    Dim sTable As StyledTable = CType(Component, StyledTable)
    Dim designTimeHTML As String
    Dim rows As TableRowCollection = sTable.Rows
    Dim cellsWithDummyContents As ArrayList = Nothing
   
    Dim emptyTable As Boolean = rows.Count = 0
    Dim emptyRows As Boolean = False
    Dim counter As Integer = 1
    Dim numcells As Integer = 2
    
    Try     
        ' Create two cells to display
        ' in a row at design time.
        If emptyTable Then
            Dim row As TableRow = New TableRow()
            rows.Add(row)
      
            Dim i As Integer
            For i = 0 To numcells - 1
                Dim c As TableCell = New TableCell()
                c.Text = "Cell #" & counter.ToString()
                counter += 1
                rows(0).Cells.Add(c)
            Next i
        Else
            emptyRows = True
            Dim j As Integer
            For j = 0 To rows.Count - 1
                If rows(j).Cells.Count <> 0 Then
                    emptyRows = False
                    Exit For
                End If
            Next j
            If emptyRows = True Then
                Dim k As Integer
                For k = 0 To numcells - 1
                    Dim c As TableCell = New TableCell()
                    c.Text = "Cell #" & counter.ToString()
                    counter += 1
                    rows(0).Cells.Add(c)
                Next k
             End If
        End If
   
        If emptyTable = False Then
            ' If the rows and cells were defined by the user, but the
            ' cells remain empty this code defines a string to display 
            ' in them at design time.
            Dim row As TableRow
            For Each row In rows
                Dim c As TableCell
                For Each c In row.Cells
                    If ((c.Text.Length = 0) AndAlso (c.HasControls() = False)) Then
                       If cellsWithDummyContents Is Nothing Then
                           cellsWithDummyContents = New ArrayList()
                       End If
                       cellsWithDummyContents.Add(c)
                       c.Text = "Cell #" & counter.ToString()
                       counter += 1
                    End If
                Next c
            Next row
        End If
        ' Retrieve the design-time HTML for the StyledTable class.
        designTimeHTML = MyBase.GetDesignTimeHtml()

    Finally
        ' If the StyledTable was empty before the dummy text was added,
        ' restore it to that state.
        If emptyTable Then
            rows.Clear()
        Else
            ' Clear the cells that were empty before the dummy text 
            ' was added.
            If Not (cellsWithDummyContents Is Nothing) Then
                Dim c As TableCell
                For Each c In  cellsWithDummyContents
                    c.Text = [String].Empty
                Next c
            End If
            If emptyRows Then
                rows(0).Cells.Clear()
            End If
        End If
   
    End Try
    Return designTimeHTML
End Function

[C#, C++, JScript] C#、C++、および JScript のサンプルはありません。Visual Basic のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ

.NET Framework セキュリティ:

参照

TableDesigner クラス | TableDesigner メンバ | System.Web.UI.Design.WebControls 名前空間 | Table