GridViewDesigner 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在可视化设计器中为 GridView 控件提供设计时支持。
public ref class GridViewDesigner : System::Web::UI::Design::WebControls::DataBoundControlDesignerpublic class GridViewDesigner : System.Web.UI.Design.WebControls.DataBoundControlDesignertype GridViewDesigner = class
    inherit DataBoundControlDesignerPublic Class GridViewDesigner
Inherits DataBoundControlDesigner- 继承
示例
下面的代码示例演示如何扩展 GridViewDesigner 类,以在设计时更改派生自 控件的 GridView 控件的外观。
该示例从 GridView派生MyGridView控件。 只是 MyGridView 的副本 GridView。 该示例还从 类派生MyGridViewDesigner类,GridViewDesigner并在 控件上MyGridView放置 一MyGridViewDesigner个 DesignerAttribute 对象。
重写 MyGridViewDesigner 方法, PreFilterProperties 使 Page 属性在设计时在 “属性” 网格中可见。 它会重写 方法,GetDesignTimeHtml以在设计时将 属性作为控件中的MyGridView新第一行包含在Caption内(如果已指定)。 
              BorderStyle如果 控件的 MyGridView 属性具有 NotSet 或 None 值, 将在GetDesignTimeHtml控件周围绘制蓝色虚线边框,使其范围更可见。
using System;
using System.Web;
using System.Drawing;
using System.Web.UI.WebControls;
using System.Web.UI.Design.WebControls;
using System.Collections;
using System.ComponentModel;
using System.Security.Permissions;
namespace Examples.CS.WebControls.Design
{
    // The MyGridView is a copy of the GridView.
    [AspNetHostingPermission(SecurityAction.Demand, 
        Level = AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, 
        Level = AspNetHostingPermissionLevel.Minimal)]
    [Designer(typeof(Examples.CS.WebControls.Design.MyGridViewDesigner))]
    public class MyGridView : GridView
    {
    } // MyGridView
    // Override members of the GridViewDesigner.
    [ReflectionPermission(SecurityAction.Demand, Flags=ReflectionPermissionFlag.MemberAccess)]
    public class MyGridViewDesigner : GridViewDesigner
    {
        // Shadow the control properties with design-time properties.
        protected override void PreFilterProperties(IDictionary properties)
        {
            // Call the base method first.
            base.PreFilterProperties(properties);
            // Make the Page visible in the Properties grid.
            PropertyDescriptor selectProp = 
                (PropertyDescriptor)properties["Page"];
            properties["Page"] =
                TypeDescriptor.CreateProperty(selectProp.ComponentType, 
                    selectProp, BrowsableAttribute.Yes);
        } // PreFilterProperties
        // 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
    } // MyGridViewDesigner
} // Examples.CS.WebControls.Design
Imports System.Web
Imports System.Drawing
Imports System.Web.UI.WebControls
Imports System.Web.UI.Design.WebControls
Imports System.Collections
Imports System.ComponentModel
Imports System.Security.Permissions
Namespace Examples.VB.WebControls.Design
    ' The MyGridView is a copy of the GridView.
    <AspNetHostingPermission(SecurityAction.Demand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    <Designer(GetType(Examples.VB.WebControls.Design.MyGridViewDesigner))> _
    Public Class MyGridView
        Inherits GridView
    End Class
    ' Override members of the GridViewDesigner.
    <ReflectionPermission(SecurityAction.Demand, Flags:=ReflectionPermissionFlag.MemberAccess)> _
    Public Class MyGridViewDesigner
        Inherits GridViewDesigner
        ' Shadow the control properties with design-time properties.
        Protected Overrides Sub PreFilterProperties( _
            ByVal properties As IDictionary)
            ' Call the base method first.
            MyBase.PreFilterProperties(properties)
            ' Make the Page visible in the Properties grid.
            Dim selectProp As PropertyDescriptor = _
                CType(properties("Page"), PropertyDescriptor)
            properties("Page") = _
                TypeDescriptor.CreateProperty(selectProp.ComponentType, _
                    selectProp, BrowsableAttribute.Yes)
        End Sub
        ' 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
    End Class
End Namespace ' Examples.VB.WebControls.Design
注解
在可视化设计器中,从“源”视图切换到“设计”视图时,将分析描述控件的 GridView 标记源代码,并在设计图面上创建控件的设计时版本。 切换回源视图时,设计时控件将保留到标记源代码中,并编辑到网页的标记中。
类的属性 GridViewDesigner 提供以下功能:
- 属性 ActionLists 返回 一个 DesignerActionListCollection 对象,该对象通常包含从 DesignerActionList 设计器继承树中每个级别的 类派生的对象。 
- 属性 AutoFormats 返回用于在“ 自动格式 ”对话框中显示的格式设置方案的集合。 
- 属性 TemplateGroups 返回关联 GridView 控件和顶级 GridView 模板的字段的模板组集合。 
- 属性 UsePreviewControl 始终返回 - true,指示设计器创建关联的 GridView 的临时副本以生成设计时标记。
类的方法 GridViewDesigner 提供以下功能:
- 方法 GetDesignTimeHtml 返回用于在设计时呈现关联的 GridView 的标记。 
- 方法 Initialize 使设计器准备好查看、编辑和设计关联的 GridView。 
- OnSchemaRefreshed当关联的GridView数据源的架构发生更改时,将调用 方法。 
- 方法 PreFilterProperties 用于删除或添加属性或隐藏关联 GridView的属性。 
控件不支持 GridView 设计时可编辑区域,因此 GetEditableDesignerRegionContent 和 SetEditableDesignerRegionContent 方法没有功能。
构造函数
| GridViewDesigner() | 初始化 GridViewDesigner 类的新实例。 | 
属性
| ActionLists | 获取或设置此设计器的设计器操作列表集合。 | 
| AllowResize | 获取一个值,该值指示是否可以在设计时环境中调整控件的大小。(继承自 ControlDesigner) | 
| AssociatedComponents | 获取与设计器所管理的组件关联的组件集合。(继承自 ComponentDesigner) | 
| AutoFormats | 获取或设置预定义的格式设置方案的集合,以便在“自动套用格式”对话框中显示。 | 
| Behavior | 
		已过时.
	 获取或设置与设计器关联的 DHTML 行为。(继承自 HtmlControlDesigner) | 
| Component | 获取此设计器正在设计的组件。(继承自 ComponentDesigner) | 
| DataBindings | 获取当前控件的数据绑定集合。(继承自 HtmlControlDesigner) | 
| DataBindingsEnabled | 获取一个值,该值指示包含关联控件的区域是否支持数据绑定。(继承自 ControlDesigner) | 
| DataMember | 获取基础数据绑定控件的隐藏 DataMember 属性。(继承自 DataBoundControlDesigner) | 
| DataSource | 获取或设置关联控件的 DataSource 属性值。(继承自 BaseDataBoundControlDesigner) | 
| DataSourceDesigner | 获取基础数据绑定控件的数据源的设计器。(继承自 DataBoundControlDesigner) | 
| DataSourceID | 获取或设置基础 DataSourceID 对象的 BaseDataBoundControl 属性值。(继承自 BaseDataBoundControlDesigner) | 
| DesignerState | 获取用于在设计时保持关联控件数据的对象。(继承自 ControlDesigner) | 
| DesignerView | 获取与此设计器的数据源相关联的 DesignerDataSourceView 对象。(继承自 DataBoundControlDesigner) | 
| DesignTimeElement | 
		已过时.
	 获取一个设计时对象,该对象表示与设计图面上的 HtmlControlDesigner 对象关联的控件。(继承自 HtmlControlDesigner) | 
| DesignTimeElementView | 
		已过时.
	 获取控件设计器的视图控件对象。(继承自 ControlDesigner) | 
| DesignTimeHtmlRequiresLoadComplete | 
		已过时.
	 获取一个值,该值指示是否必须在设计宿主完成加载之后才能调用 GetDesignTimeHtml 方法。(继承自 ControlDesigner) | 
| Expressions | 获取当前控件在设计时的表达式绑定。(继承自 HtmlControlDesigner) | 
| HidePropertiesInTemplateMode | 获取一个值,该值指示当控件处于模板模式时,关联控件的属性是否被隐藏。(继承自 ControlDesigner) | 
| ID | 获取或设置控件的 ID 字符串。(继承自 ControlDesigner) | 
| InheritanceAttribute | 获取一个特性,该特性指示关联组件的继承类型。(继承自 ComponentDesigner) | 
| Inherited | 获取一个值,该值指示是否继承此组件。(继承自 ComponentDesigner) | 
| InTemplateMode | 获取一个值,该值指示控件在设计宿主中是否处于模板查看模式或模板编辑模式之一。 InTemplateMode 属性为只读。(继承自 ControlDesigner) | 
| IsDirty | 
		已过时.
	 获取或设置一个值,该值指示 Web 服务器控件是否已被标记为已更改。(继承自 ControlDesigner) | 
| ParentComponent | 获取此设计器的父组件。(继承自 ComponentDesigner) | 
| ReadOnly | 
		已过时.
	 获取或设置一个值,该值指示控件的属性在设计时是否为只读。(继承自 ControlDesigner) | 
| RootDesigner | 获取包含关联控件的 Web 窗体页的控件设计器。(继承自 ControlDesigner) | 
| SampleRowCount | 获取或设置要显示的关联控件的示例行数。 | 
| SetTextualDefaultProperty | 在可视化设计器中为 GridView 控件提供设计时支持。(继承自 ComponentDesigner) | 
| ShadowProperties | 获取重写用户设置的属性值的集合。(继承自 ComponentDesigner) | 
| ShouldCodeSerialize | 
		已过时.
	 获取或设置一个值,该值指示在序列化期间是否应为当前设计文档在代码隐藏文件中创建控件的字段声明。(继承自 HtmlControlDesigner) | 
| Tag | 获取表示关联控件的 HTML 标记元素的对象。(继承自 ControlDesigner) | 
| TemplateGroups | 获取或设置用于关联控件字段的模板组集合。 | 
| UseDataSourcePickerActionList | 获取一个值,该值指示设计器是否在其操作列表中包括“选择一个数据源”。(继承自 DataBoundControlDesigner) | 
| UsePreviewControl | 获取一个值,该值指示设计器是否应使用临时副本取代与设计器关联的实际控件来生成设计时标记。 | 
| Verbs | 获取与设计器相关联的组件所支持的设计时谓词。(继承自 ComponentDesigner) | 
| ViewControl | 获取或设置可用于预览设计时 HTML 标记的 Web 服务器控件。(继承自 ControlDesigner) | 
| ViewControlCreated | 获取或设置一个值,该值指示是否已创建  | 
| Visible | 获取指示该控件在设计时是否可见的值。(继承自 ControlDesigner) |