DetailsViewDesigner.GetDesignTimeHtml Metoda
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Pobiera znaczniki używane do renderowania skojarzonej DetailsView kontrolki w czasie projektowania.
Przeciążenia
GetDesignTimeHtml() |
Pobiera znaczniki używane do renderowania skojarzonej kontrolki w czasie projektowania. |
GetDesignTimeHtml(DesignerRegionCollection) |
Pobiera znaczniki używane do renderowania skojarzonej kontrolki w czasie projektowania i wypełnia kolekcję regionów projektanta. |
GetDesignTimeHtml()
Pobiera znaczniki używane do renderowania skojarzonej kontrolki w czasie projektowania.
public:
override System::String ^ GetDesignTimeHtml();
public override string GetDesignTimeHtml ();
override this.GetDesignTimeHtml : unit -> string
Public Overrides Function GetDesignTimeHtml () As String
Zwraca
Element String zawierający znaczniki używane do renderowania DetailsView w czasie projektowania.
Przykłady
Poniższy przykład kodu pokazuje, jak zastąpić metodę GetDesignTimeHtml w klasie dziedziczonej z DetailsViewDesigner klasy w celu zmiany wyglądu DetailsView kontrolki w czasie projektowania. W przykładzie do siatki Caption zostanie dodany nowy pierwszy wiersz zawierający właściwość , jeśli Caption element jest zdefiniowany. BorderStyle Jeśli właściwość kontrolki pochodzącej z DetailsView klasy jest wartością NotSet lubNone, GetDesignTimeHtml rysuje niebieskie obramowanie kreskowane wokół kontrolki, aby jego zakres był bardziej widoczny. Nie zmienia wyglądu kontrolki w czasie wykonywania.
// 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
Uwagi
GetDesignTimeHtml() Najpierw metoda ustawia AutoGenerateRows właściwość kontrolki DetailsView na true
, jeśli kolekcja jest pustaFields. Następnie GetDesignTimeHtml ustawia DataKeyNames kolekcję kontrolki GetDesignTimeHtml na pustą String tablicę, jeśli nie można uzyskać schematu źródła danych. Odświeża obiekt, TypeDescriptor aby wymusić wywołanie PreFilterProperties metody. Następnie wywołuje metodę podstawową, aby wygenerować adiustację.
Uwagi dotyczące dziedziczenia
Jeśli przesłonisz metodę GetDesignTimeHtml() , pamiętaj, aby wywołać metodę podstawową, ponieważ ostatecznie, za pomocą kilku poziomów przesłonięcia, wywołuje DetailsView kontrolkę lub kopię kontrolki, aby wygenerować znaczniki.
Zobacz też
Dotyczy
GetDesignTimeHtml(DesignerRegionCollection)
Pobiera znaczniki używane do renderowania skojarzonej kontrolki w czasie projektowania i wypełnia kolekcję regionów projektanta.
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
Parametry
- regions
- DesignerRegionCollection
Element DesignerRegionCollection , do którego należy dodać definicje wybranych i możliwych do kliknięcia regionów w widoku czasu projektowania kontrolki.
Zwraca
Element String zawierający znaczniki używane do renderowania DetailsView w czasie projektowania.
Przykłady
Poniższy przykład kodu pokazuje, jak zastąpić metodę GetDesignTimeHtml w klasie dziedziczonej z DetailsViewDesigner klasy w celu zmiany wyglądu DetailsView kontrolki w czasie projektowania. W przykładzie do siatki Caption zostanie dodany nowy pierwszy wiersz zawierający właściwość , jeśli Caption element jest zdefiniowany. BorderStyle Jeśli właściwość kontrolki pochodzącej z DetailsView kontrolki jest wartością NotSet lubNone, GetDesignTimeHtml rysuje niebieskie obramowanie kreskowane wokół kontrolki, aby jego zakres był bardziej widoczny. Nie zmienia wyglądu kontrolki w czasie wykonywania.
// 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
Uwagi
Metoda DetailsViewDesigner.GetDesignTimeHtml wywołuje metodę DetailsViewDesigner.GetDesignTimeHtml w celu wygenerowania znaczników dla renderowania kontrolki w DetailsView czasie projektowania. Metoda DetailsViewDesigner.GetDesignTimeHtml jest również wypełniana regions
obiektem DesignerRegion dla każdego możliwego do kliknięcia lub wybranego regionu renderowania w czasie projektowania.
Dla obiektu można zaznaczyć pierwszą DetailsViewkomórkę w każdym wierszu. Wszystkie komórki w wierszach można klikać.
Uwagi dotyczące dziedziczenia
Jeśli przesłonisz metodę GetDesignTimeHtml(DesignerRegionCollection) , pamiętaj, aby wywołać metodę podstawową lub GetDesignTimeHtml() przeciążenie, ponieważ ostatecznie, za pomocą kilku poziomów przesłonięcia, wywołaj DetailsView kontrolkę lub kopię kontrolki, aby wygenerować znaczniki.