DataListDesigner Class
Extends design-time behavior for the DataList Web server control.
Assembly: System.Design (in System.Design.dll)
The following code example demonstrates how to extend the DataListDesigner class. The code overrides the GetDesignTimeHtml method to display a five-point border that is purple if the DataList control is enabled.
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; ... 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); } } }
The following code example shows how to use the DesignerAttribute to associate the designer with the DataList control.
- SecurityPermission
for calling unmanaged code. Demand value: Demand. Permission value: UnmanagedCode
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.