GridViewDesigner.GetDesignTimeHtml 方法      
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取用于在设计时呈现关联的 GridView 控件的标记。
重载
| GetDesignTimeHtml() | 获取用于在设计时呈现关联控件的标记。 | 
| GetDesignTimeHtml(DesignerRegionCollection) | 获取用于在设计时呈现关联控件的标记,并填充设计器区域的集合。 | 
GetDesignTimeHtml()
获取用于在设计时呈现关联控件的标记。
public:
 override System::String ^ GetDesignTimeHtml();public override string GetDesignTimeHtml();override this.GetDesignTimeHtml : unit -> stringPublic Overrides Function GetDesignTimeHtml () As String返回
一个 String,其中包含用于在设计时呈现 GridView 的标记。
示例
下面的代码示例演示如何重写 GetDesignTimeHtml 从 GridViewDesigner 类继承的 类中的 方法,以在设计时更改控件的外观 GridView 。 该示例在网格中添加一个新第一行,以包含 Caption 属性(如果 Caption 已定义)。 BorderStyle如果派生自 GridView 类的控件的 属性具有 NotSet 或 None 值,则会GetDesignTimeHtml在控件周围绘制蓝色虚线边框,使其范围更可见。 它不会更改控件的运行时外观。
// Generate the design-time markup.
const string capTag = "caption";
const string trOpen = "tr><td colspan=9 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.
    MyGridView myGV = (MyGridView)Component;
    string markup = null;
    int charX;
    // Check if the border style should be changed.
    if (myGV.BorderStyle == BorderStyle.NotSet ||
        myGV.BorderStyle == BorderStyle.None)
    {
        BorderStyle oldBorderStyle = myGV.BorderStyle;
        Unit oldBorderWidth = myGV.BorderWidth;
        Color oldBorderColor = myGV.BorderColor;
        // Set the design-time properties and catch any exceptions.
        try
        {
            myGV.BorderStyle = BorderStyle.Dashed;
            myGV.BorderWidth = Unit.Pixel(3);
            myGV.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.
            myGV.BorderStyle = oldBorderStyle;
            myGV.BorderWidth = oldBorderWidth;
            myGV.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=9 align=center".
        // It is okay if the colspan exceeds the 
        // number of columns in the table.
        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=9 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 myGV As MyGridView = CType(Component, MyGridView)
    Dim markup As String = Nothing
    Dim charX As Integer
    ' Check if the border style should be changed.
    If (myGV.BorderStyle = BorderStyle.NotSet Or _
        myGV.BorderStyle = BorderStyle.None) Then
        Dim oldBorderStyle As BorderStyle = myGV.BorderStyle
        Dim oldBorderWidth As Unit = myGV.BorderWidth
        Dim oldBorderColor As Color = myGV.BorderColor
        ' Set the design-time properties and catch any exceptions.
        Try
            myGV.BorderStyle = BorderStyle.Dashed
            myGV.BorderWidth = Unit.Pixel(3)
            myGV.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.
            myGV.BorderStyle = oldBorderStyle
            myGV.BorderWidth = oldBorderWidth
            myGV.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=9 align=center".
        ' It is okay if the colspan exceeds the 
        ' number of columns in the table.
        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() 方法执行以下操作:
- AutoGenerateColumns如果 属性为空,则将 控件的 Columns 属性设置为 - true。
- DataKeyNames如果无法获取数据源的架构,则将 控件的 属性设置为 - null。
- TypeDescriptor刷新 对象以强制PreFilterProperties调用 方法。 
- 调用基方法以生成标记。 
继承者说明
如果重写 GetDesignTimeHtml() 方法,请务必调用基方法,因为它最终会通过多个重写级别调用 GridView 控件或控件的副本来生成标记。
另请参阅
适用于
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 -> stringPublic Overrides Function GetDesignTimeHtml (regions As DesignerRegionCollection) As String参数
- regions
- DesignerRegionCollection
一个 DesignerRegionCollection,将在其中添加控件设计时视图中定义的可选择和可单击区域。
返回
一个 String,其中包含用于在设计时呈现 GridView 的标记。
示例
下面的代码示例演示如何重写 GetDesignTimeHtml 从 GridViewDesigner 类继承的 类中的 方法,以在设计时更改控件的外观 GridView 。 该示例在网格中添加一个新第一行,以包含 Caption 属性(如果 Caption 已定义)。 BorderStyle如果派生自 GridView 类的控件的 属性具有 NotSet 或 None 值,则会GetDesignTimeHtml在控件周围绘制蓝色虚线边框,使其范围更可见。 它不会更改控件的运行时外观。
// Generate the design-time markup.
const string capTag = "caption";
const string trOpen = "tr><td colspan=9 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.
    MyGridView myGV = (MyGridView)Component;
    string markup = null;
    int charX;
    // Check if the border style should be changed.
    if (myGV.BorderStyle == BorderStyle.NotSet ||
        myGV.BorderStyle == BorderStyle.None)
    {
        BorderStyle oldBorderStyle = myGV.BorderStyle;
        Unit oldBorderWidth = myGV.BorderWidth;
        Color oldBorderColor = myGV.BorderColor;
        // Set the design-time properties and catch any exceptions.
        try
        {
            myGV.BorderStyle = BorderStyle.Dashed;
            myGV.BorderWidth = Unit.Pixel(3);
            myGV.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.
            myGV.BorderStyle = oldBorderStyle;
            myGV.BorderWidth = oldBorderWidth;
            myGV.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=9 align=center".
        // It is okay if the colspan exceeds the 
        // number of columns in the table.
        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=9 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 myGV As MyGridView = CType(Component, MyGridView)
    Dim markup As String = Nothing
    Dim charX As Integer
    ' Check if the border style should be changed.
    If (myGV.BorderStyle = BorderStyle.NotSet Or _
        myGV.BorderStyle = BorderStyle.None) Then
        Dim oldBorderStyle As BorderStyle = myGV.BorderStyle
        Dim oldBorderWidth As Unit = myGV.BorderWidth
        Dim oldBorderColor As Color = myGV.BorderColor
        ' Set the design-time properties and catch any exceptions.
        Try
            myGV.BorderStyle = BorderStyle.Dashed
            myGV.BorderWidth = Unit.Pixel(3)
            myGV.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.
            myGV.BorderStyle = oldBorderStyle
            myGV.BorderWidth = oldBorderWidth
            myGV.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=9 align=center".
        ' It is okay if the colspan exceeds the 
        ' number of columns in the table.
        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(DesignerRegionCollection) 调用 GetDesignTimeHtml() 方法,为控件的设计时呈现 GridView 生成标记。 还会 GetDesignTimeHtml(DesignerRegionCollection) 为设计时呈现的每个可单击或可选择区域填充 regions 一个 DesignerRegion 对象。
对于 , GridView可以选择每行中的第一个单元格;行中的所有单元格都可以单击。
继承者说明
如果重写 GetDesignTimeHtml(DesignerRegionCollection) 方法,请务必调用基方法或 GetDesignTimeHtml() 重载,因为它们最终会通过多个重写级别调用 GridView 控件或控件的副本来生成标记。