Export (0) Print
Expand All

DataListDesigner Class

Extends design-time behavior for the DataList Web server control.

Namespace: System.Web.UI.Design.WebControls
Assembly: System.Design (in system.design.dll)

public class DataListDesigner : BaseDataListDesigner
public class DataListDesigner extends BaseDataListDesigner
public class DataListDesigner extends BaseDataListDesigner

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.

[ Designer("ASPNET.Examples.Design.SimpleGridViewDesigner", 
        "System.Web.UI.Design.GridViewDesigner")]
public class SimpleGridView : GridView
{
    // Code to customize your GridView goes here
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Show:
© 2014 Microsoft