DataListDesigner.GetDesignTimeHtml Metode
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan HTML yang digunakan untuk mewakili kontrol pada DataList waktu desain.
public:
override System::String ^ GetDesignTimeHtml();
public override string GetDesignTimeHtml ();
override this.GetDesignTimeHtml : unit -> string
Public Overrides Function GetDesignTimeHtml () As String
Mengembalikan
HTML yang digunakan untuk mewakili kontrol pada DataList waktu desain.
Contoh
Contoh kode berikut menunjukkan cara mengambil GetDesignTimeHtml alih metode . Ini mengubah tampilan kontrol pada permukaan desain jika properti kontrol WebControl.Enabled adalah true
.
Kode menggunakan Try...Catch...Finally
sintaks untuk melakukan hal berikut:
Bagian
Try
mengubah nilai properti kontrol.Bagian ini
Catch
menangkap pengecualian apa pun dan mengirimkannya ke GetErrorDesignTimeHtml metode .Bagian
Finally
mengatur properti ke nilai aslinya.
Contoh kode ini adalah bagian dari contoh yang lebih besar yang disediakan untuk DataListDesigner kelas .
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
Berlaku untuk
Lihat juga
Saran dan Komentar
https://aka.ms/ContentUserFeedback.
Segera hadir: Sepanjang tahun 2024 kami akan menghentikan penggunaan GitHub Issues sebagai mekanisme umpan balik untuk konten dan menggantinya dengan sistem umpan balik baru. Untuk mengetahui informasi selengkapnya, lihat:Kirim dan lihat umpan balik untuk