DetailsViewDesigner.GetDesignTimeHtml 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取用于在设计时呈现关联的 DetailsView 控件的标记。
重载
GetDesignTimeHtml() |
获取用于在设计时呈现关联控件的标记。 |
GetDesignTimeHtml(DesignerRegionCollection) |
获取用于在设计时呈现关联控件的标记,并填充设计器区域的集合。 |
GetDesignTimeHtml()
获取用于在设计时呈现关联控件的标记。
public:
override System::String ^ GetDesignTimeHtml();
public override string GetDesignTimeHtml ();
override this.GetDesignTimeHtml : unit -> string
Public Overrides Function GetDesignTimeHtml () As String
返回
一个 String,其中包含用于在设计时呈现 DetailsView 的标记。
示例
下面的代码示例演示如何重写 GetDesignTimeHtml 从 DetailsViewDesigner 类继承的类中的 方法,以在设计时更改控件的外观 DetailsView 。 该示例在网格中添加一个新第一行以包含 Caption 属性(如果 Caption 已定义)。 BorderStyle如果派生自 DetailsView 的控件的 属性是 NotSet 或 None 值,则 将在GetDesignTimeHtml控件周围绘制蓝色虚线边框,使其范围更加可见。 它不会更改控件的运行时外观。
// 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
注解
首先,GetDesignTimeHtml()如果集合为空, 方法将 DetailsView 控件的 属性设置为 AutoGenerateRowstrue
。Fields
GetDesignTimeHtml如果无法获取数据源的架构,GetDesignTimeHtml则 将 控件的集合设置为DataKeyNames空String数组。 它刷新 TypeDescriptor 对象以强制 PreFilterProperties 调用 方法。 然后,它调用基方法以生成标记。
继承者说明
如果重写 GetDesignTimeHtml() 方法,请务必调用基方法,因为它最终会通过多个重写级别调用 DetailsView 控件或控件的副本来生成标记。
另请参阅
适用于
GetDesignTimeHtml(DesignerRegionCollection)
获取用于在设计时呈现关联控件的标记,并填充设计器区域的集合。
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
参数
- regions
- DesignerRegionCollection
一个 DesignerRegionCollection,它将向其中添加控件设计时视图的可选择和可单击区域的定义。
返回
一个 String,其中包含用于在设计时呈现 DetailsView 的标记。
示例
下面的代码示例演示如何重写 GetDesignTimeHtml 从 DetailsViewDesigner 类继承的类中的 方法,以在设计时更改控件的外观 DetailsView 。 该示例在网格中添加一个新第一行以包含 Caption 属性(如果 Caption 已定义)。 BorderStyle如果派生自 DetailsView 的控件的 属性为 NotSet 或 None 值,则 将在GetDesignTimeHtml控件周围绘制蓝色虚线边框,使其范围更加可见。 它不会更改控件的运行时外观。
// 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
注解
方法 DetailsViewDesigner.GetDesignTimeHtml 调用 DetailsViewDesigner.GetDesignTimeHtml 方法,为控件的设计时呈现 DetailsView 生成标记。 方法 DetailsViewDesigner.GetDesignTimeHtml 还为设计时呈现的每个可单击或可选区域填充 regions
一个 DesignerRegion 对象。
DetailsView对于 ,可以选择每行中的第一个单元格;行中的所有单元格都可以单击。
继承者说明
如果重写 GetDesignTimeHtml(DesignerRegionCollection) 方法,请务必调用基方法或 GetDesignTimeHtml() 重载,因为它们最终会通过多个替代级别对 控件或控件的副本调用 DetailsView 以生成标记。