DataGridDesigner 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
扩展 Web 服务器控件的设计时行为 DataGrid 。
public ref class DataGridDesigner : System::Web::UI::Design::WebControls::BaseDataListDesigner
public class DataGridDesigner : System.Web.UI.Design.WebControls.BaseDataListDesigner
[System.Web.UI.Design.SupportsPreviewControl(true)]
public class DataGridDesigner : System.Web.UI.Design.WebControls.BaseDataListDesigner
type DataGridDesigner = class
inherit BaseDataListDesigner
[<System.Web.UI.Design.SupportsPreviewControl(true)>]
type DataGridDesigner = class
inherit BaseDataListDesigner
Public Class DataGridDesigner
Inherits BaseDataListDesigner
- 继承
- 属性
示例
下面的代码示例演示如何扩展 DataGridDesigner 类。 代码重写GetDesignTimeHtml在设计图面上呈现控件时CellPadding自定义BorderWidthBorderColor和DataGrid属性的方法。
Imports System.Diagnostics
Imports System.ComponentModel
Imports System.Drawing
Imports System.Web.UI.Design.WebControls
Imports System.Web.UI.WebControls
Namespace Examples.AspNet
' Create a designer class for the SimpleDataList class.
<System.Security.Permissions.SecurityPermission( _
System.Security.Permissions.SecurityAction.Demand, _
Flags:=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)> _
Public Class SimpleDataListDesigner
Inherits DataListDesigner
Private simpleList As SimpleDataList
' Override the GetDesignTimeHtml method to add style to the control
' on the design surface.
Public Overrides Function GetDesignTimeHtml() As String
' Cast the control to the Component property of the designer.
simpleList = CType(Component, SimpleDataList)
Dim designTimeHtml As String = Nothing
' Create variables to hold current property values.
Dim oldBorderWidth As Unit = simpleList.BorderWidth
Dim oldBorderColor As Color = simpleList.BorderColor
' Set the properties and generate the design-time HTML.
If (simpleList.Enabled) Then
Try
simpleList.BorderWidth = Unit.Point(5)
simpleList.BorderColor = Color.Purple
designTimeHtml = MyBase.GetDesignTimeHtml()
' Call the GetErrorDesignTimeHtml method if an
' exception occurs.
Catch ex As Exception
designTimeHtml = GetErrorDesignTimeHtml(ex)
' Return the properties to their original settings.
Finally
simpleList.BorderWidth = oldBorderWidth
simpleList.BorderColor = oldBorderColor
End Try
' If the list is not enabled, call the GetEmptyDesignTimeHtml
' method.
Else
designTimeHtml = GetEmptyDesignTimeHtml()
End If
Return designTimeHtml
End Function
Protected Overrides Function GetEmptyDesignTimeHtml() As String
Dim emptyText As String
' Check the CanEnterTemplateMode property to
' specify which text to display if ItemTemplate
' does not contain a value.
If CanEnterTemplateMode Then
emptyText = _
"<b>Either the Enabled property value is false " + _
"or you need to set the ItemTemplate for this " + _
"control.<br>Right-click to edit templates.</b>"
Else
emptyText = _
"<b>You cannot edit templates in this view.<br>" + _
"Switch to HTML view to define the ItemTemplate.</b>"
End If
Return CreatePlaceHolderDesignTimeHtml(emptyText)
End Function
' Generate HTML to indicate that an error has occurred.
Protected Overrides Function GetErrorDesignTimeHtml(ByVal exc As _
Exception) As String
Return CreatePlaceHolderDesignTimeHtml( _
"<b>An error occurred</b>.<br>Check to ensure that all " + _
"properties are valid.")
End Function
' Override the Initialize method to ensure that
' only an instance of the SimpleDataList class is
' used by this designer class.
Public Overrides Sub Initialize(ByVal component As IComponent)
simpleList = CType(component, SimpleDataList)
If IsNothing(simpleList) Then
Throw New ArgumentException("Must be a SimpleDataList.", "component")
End If
MyBase.Initialize(component)
End Sub
End Class
End Namespace
以下示例演示如何使用 DesignerAttribute 特性将设计器与 DataGrid 控件相关联。
' Override the Initialize method to ensure that
' only an instance of the SimpleDataList class is
' used by this designer class.
Public Overrides Sub Initialize(ByVal component As IComponent)
simpleList = CType(component, SimpleDataList)
If IsNothing(simpleList) Then
Throw New ArgumentException("Must be a SimpleDataList.", "component")
End If
MyBase.Initialize(component)
End Sub
构造函数
| 名称 | 说明 |
|---|---|
| DataGridDesigner() |
初始化 DataGridDesigner 类的新实例。 |