Bagikan melalui


DetailsViewDesigner.GetDesignTimeHtml Metode

Definisi

Mendapatkan markup yang digunakan untuk merender kontrol terkait DetailsView pada waktu desain.

Overload

Nama Deskripsi
GetDesignTimeHtml()

Mendapatkan markup yang digunakan untuk merender kontrol terkait pada waktu desain.

GetDesignTimeHtml(DesignerRegionCollection)

Mendapatkan markup yang digunakan untuk merender kontrol terkait pada waktu desain dan mengisi kumpulan wilayah desainer.

GetDesignTimeHtml()

Mendapatkan markup yang digunakan untuk merender kontrol terkait pada waktu desain.

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

Mengembalikan

Yang String berisi markup yang digunakan untuk merender DetailsView pada waktu desain.

Contoh

Contoh kode berikut menunjukkan cara mengambil alih GetDesignTimeHtml metode di kelas yang diwarisi dari DetailsViewDesigner kelas untuk mengubah tampilan DetailsView kontrol pada waktu desain. Contoh menambahkan baris pertama baru ke kisi untuk berisi Caption properti , jika Caption ditentukan. BorderStyle Jika properti kontrol yang berasal dari DetailsView adalah NotSet nilai atau None , GetDesignTimeHtml gambar batas putus-putus biru di sekitar kontrol untuk membuat tingkatnya lebih terlihat. Ini tidak mengubah tampilan run-time kontrol.

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

Keterangan

Pertama, GetDesignTimeHtml() metode mengatur AutoGenerateRows properti DetailsView kontrol ke true, jika Fields koleksi kosong. Kemudian GetDesignTimeHtml mengatur DataKeyNames kumpulan GetDesignTimeHtml kontrol ke array kosong String jika skema sumber data tidak dapat diperoleh. Ini me-refresh TypeDescriptor objek untuk memaksa metode untuk PreFilterProperties dipanggil. Kemudian memanggil metode dasar untuk menghasilkan markup.

Catatan Bagi Inheritor

Jika Anda mengambil GetDesignTimeHtml() alih metode , pastikan untuk memanggil metode dasar karena pada akhirnya, melalui beberapa tingkat penimpaan, panggilan pada DetailsView kontrol atau salinan kontrol untuk menghasilkan markup.

Lihat juga

Berlaku untuk

GetDesignTimeHtml(DesignerRegionCollection)

Mendapatkan markup yang digunakan untuk merender kontrol terkait pada waktu desain dan mengisi kumpulan wilayah desainer.

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

Parameter

regions
DesignerRegionCollection

DesignerRegionCollection untuk menambahkan definisi wilayah yang dapat dipilih dan dapat diklik dalam tampilan waktu desain kontrol.

Mengembalikan

Yang String berisi markup yang digunakan untuk merender DetailsView pada waktu desain.

Contoh

Contoh kode berikut menunjukkan cara mengambil alih GetDesignTimeHtml metode di kelas yang diwarisi dari DetailsViewDesigner kelas untuk mengubah tampilan DetailsView kontrol pada waktu desain. Contoh menambahkan baris pertama baru ke kisi untuk berisi Caption properti , jika Caption ditentukan. BorderStyle Jika properti kontrol yang berasal dari DetailsView adalah NotSet nilai atau None , GetDesignTimeHtml gambar batas putus-putus biru di sekitar kontrol untuk membuat tingkatnya lebih terlihat. Ini tidak mengubah tampilan run-time kontrol.

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

Keterangan

Metode ini DetailsViewDesigner.GetDesignTimeHtml memanggil DetailsViewDesigner.GetDesignTimeHtml metode untuk menghasilkan markup untuk penyajian DetailsView waktu desain kontrol. Metode ini DetailsViewDesigner.GetDesignTimeHtml juga diisi regions dengan DesignerRegion objek untuk setiap wilayah yang dapat diklik atau dipilih dari penyajian waktu desain.

DetailsViewUntuk , sel pertama di setiap baris dapat dipilih; semua sel dalam baris dapat diklik.

Catatan Bagi Inheritor

Jika Anda mengambil GetDesignTimeHtml(DesignerRegionCollection) alih metode , pastikan untuk memanggil metode dasar atau GetDesignTimeHtml() kelebihan beban karena pada akhirnya, melalui beberapa tingkat penimpaan, panggil DetailsView kontrol atau salinan kontrol untuk menghasilkan markup.

Lihat juga

Berlaku untuk