DataListDesigner クラス
アセンブリ: System.Design (system.design.dll 内)


DataListDesigner クラスを拡張する方法を次のコード例に示します。また、このコードは、GetDesignTimeHtml メソッドをオーバーライドして、DataList コントロールが有効なときに紫色の 5 ポイントの境界線を表示します。
Imports System Imports System.Drawing Imports System.ComponentModel Imports System.Web.UI.WebControls Imports System.Security Imports System.Web.UI.Design Imports System.Web.UI.Design.WebControls Imports Microsoft.VisualBasic Namespace ASPNET.Examples < _ Designer("ASPNET.Examples.Design.SimpleGridViewDesigner", _ "System.Web.UI.Design.GridViewDesigner") _ > _ Public Class SimpleGridView Inherits GridView ' Code to customize your GridView goes here End Class End Namespace Namespace ASPNET.Examples.Design <Permissions.SecurityPermission( _ Permissions.SecurityAction.Demand, _ Flags:=Permissions.SecurityPermissionFlag.UnmanagedCode)> _ Public Class SimpleGridViewDesigner Inherits GridViewDesigner Private simpleGView As SimpleGridView Public Overrides Function GetDesignTimeHtml() As String Dim designTimeHtml As String = String.Empty simpleGView = CType(Component, SimpleGridView) ' Check the control's BorderStyle property to ' conditionally render design-time HTML. If (simpleGView.BorderStyle = BorderStyle.NotSet) Then ' Save the current property settings in variables. Dim oldCellPadding As Integer = simpleGView.CellPadding Dim oldBorderWidth As Unit = simpleGView.BorderWidth Dim oldBorderColor As Color = simpleGView.BorderColor ' Set properties and generate the design-time HTML. Try simpleGView.Caption = "SimpleGridView" simpleGView.CellPadding = 1 simpleGView.BorderWidth = Unit.Pixel(3) simpleGView.BorderColor = Color.Red designTimeHtml = MyBase.GetDesignTimeHtml() Catch ex As Exception ' Get HTML from the GetErrorDesignTimeHtml ' method if an exception occurs. designTimeHtml = GetErrorDesignTimeHtml(ex) ' Return the properties to their original values. Finally simpleGView.CellPadding = oldCellPadding simpleGView.BorderWidth = oldBorderWidth simpleGView.BorderColor = oldBorderColor End Try Else designTimeHtml = MyBase.GetDesignTimeHtml() End If Return designTimeHtml End Function Protected Overrides Function _ GetErrorDesignTimeHtml(ByVal exc As Exception) As String Return CreatePlaceHolderDesignTimeHtml( _ "ASPNET.Examples: An error occurred while rendering the GridView.") End Function Public Overrides Sub Initialize(ByVal component As IComponent) simpleGView = CType(component, SimpleGridView) MyBase.Initialize(component) End Sub End Class End Namespace
using System; using System.Drawing; using System.Security.Permissions; using System.ComponentModel; using System.Web.UI.WebControls; using System.Web.UI.Design; using System.Web.UI.Design.WebControls; <br /><span space="preserve">...</span><br />namespace ASPNET.Examples.CS { [SecurityPermission( SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)] public class SimpleGridViewDesigner : GridViewDesigner { private SimpleGridView simpleGView; public override string GetDesignTimeHtml() { string designTimeHtml = String.Empty; simpleGView = (SimpleGridView)Component; // Check the control's BorderStyle property to // conditionally render design-time HTML. if (simpleGView.BorderStyle == BorderStyle.NotSet) { // Save the current property settings in variables. int oldCellPadding = simpleGView.CellPadding; Unit oldBorderWidth = simpleGView.BorderWidth; Color oldBorderColor = simpleGView.BorderColor; // Set properties and generate the design-time HTML. try { simpleGView.Caption = "SimpleGridView"; simpleGView.CellPadding = 1; simpleGView.BorderWidth = Unit.Pixel(3); simpleGView.BorderColor = Color.Red; designTimeHtml = base.GetDesignTimeHtml(); } catch (Exception ex) { // Get HTML from the GetErrorDesignTimeHtml // method if an exception occurs. designTimeHtml = GetErrorDesignTimeHtml(ex); // Return the properties to their original values. } finally { simpleGView.CellPadding = oldCellPadding; simpleGView.BorderWidth = oldBorderWidth; simpleGView.BorderColor = oldBorderColor; } } else designTimeHtml = base.GetDesignTimeHtml(); return designTimeHtml; } protected override string GetErrorDesignTimeHtml(System.Exception exc) { return CreatePlaceHolderDesignTimeHtml( "ASPNET.Examples: An error occurred while rendering the GridView."); } public override void Initialize(IComponent component) { simpleGView = (SimpleGridView)component; base.Initialize(component); } } }
DesignerAttribute を使用してデザイナを DataList コントロールに関連付ける方法を次のコード例に示します。

- SecurityPermission (アンマネージ コードを呼び出すために必要なアクセス許可)。要求値 : Demand。アクセス許可値 : UnmanagedCode。

System.ComponentModel.Design.ComponentDesigner
System.Web.UI.Design.HtmlControlDesigner
System.Web.UI.Design.ControlDesigner
System.Web.UI.Design.TemplatedControlDesigner
System.Web.UI.Design.WebControls.BaseDataListDesigner
System.Web.UI.Design.WebControls.DataListDesigner


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- DataListDesigner クラスのページへのリンク