This documentation is archived and is not being maintained.

DataListDesigner Class

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

For a list of all members of this type, see DataListDesigner Members.

System.Object
   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

[Visual Basic]
Public Class DataListDesigner
   Inherits BaseDataListDesigner
[C#]
public class DataListDesigner : BaseDataListDesigner
[C++]
public __gc class DataListDesigner : public BaseDataListDesigner
[JScript]
public class DataListDesigner extends BaseDataListDesigner

Thread Safety

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

Example

[Visual Basic] The following code example creates a class named SimpleDataListDesigner that inherits from the DataListDesigner class. It is used with a class named SimpleDataList that derives from the System.Web.UI.WebControls.DataList class. The code overrides the System.Web.UI.Design.WebControls.GetDesignTimeHtml method to display a five point border that is purple if the control is enabled. The designer class displays the SimpleDataList class on design surfaces, such as Visual Studio .NET.

[Visual Basic] 
' Create a designer class for the SimpleDataList
' class. The designer class inherits the DataListDesigner
' class.
Imports System
Imports System.Drawing
Imports System.Diagnostics
Imports System.Web.UI.Design.WebControls
Imports System.Web.UI.WebControls
Imports Examples.AspNet

Namespace Examples.AspNet.Design

    <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.
        Overrides Public 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 settings.
            Dim oldBorderWidth As Unit = simpleList.BorderWidth
            Dim oldBorderColor As Color = simpleList.BorderColor
                            
            ' Set properties and the design-time HTML.
            If (simpleList.Enabled) Then
                Try
                    simpleList.BorderWidth = Unit.Point(5)
                    simpleList.BorderColor = Color.Purple
                    designTimeHtml = MyBase.GetDesignTimeHtml()                    

                ' If an exception occurs, call the GetErrorDesignTimeHtml
                ' method.
                Catch ex As Exception
                    designTimeHtml = GetErrorDesignTimeHtml(ex)

                ' Return properties to their original settings. 
                Finally
                    simpleList.BorderWidth = oldBorderWidth
                    simpleList.BorderColor = oldBorderColor
                End Try
            ' Call the GetEmptyDesignTimeHtml method if 
            ' the condition is not met.
            Else
                designTimeHtml = GetEmptyDesignTimeHtml()
            End If
            
            Return designTimeHtml 
            
        End Function
 
        Overrides Protected Function GetEmptyDesignTimeHtml() As String
            Dim emptyText As String
         
            ' Check the CanEnterTemplateMode property to
            ' specify which text to display if the 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 and 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

        ' Write a string to the design surface if an error
        ' occurs while trying to render to the designer.
        Overrides Protected Function GetErrorDesignTimeHtml(exc As Exception) As String
            Debug.Fail(exc.ToString())
            
         Return CreatePlaceHolderDesignTimeHtml( _
          "<b>An error occurred!</b>.<br>Check 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(component As IComponent)
      Debug.Assert( _
        TypeOf component Is SimpleDataList, _
        "SimpleDataListDesigner::Initialize - Invalid SimpleDataList Control")
      
      simpleList = CType(component, SimpleDataList)

      MyBase.Initialize(component)
   End Sub
      
    End Class
End Namespace

[Visual Basic] The following example uses the System.ComponentModel.DesignerAttribute class to associate the SimpleDataListDesigner class with the SimpleDataList class.

[Visual Basic] 
Imports System
Imports System.ComponentModel
Imports System.Web.UI.WebControls
Imports System.Design
Imports System.Web.UI.Design.WebControls
Imports System.Security.Permissions

Namespace Examples.AspNet
    ' Associate the SimpleDataList class with
    ' its designer using the DesignerAttribute class.
    ' Use the EditorAttribute class to associate
    ' SimpleDataList using the DataListComponentEditor
    ' class.
    <DesignerAttribute( _
         GetType(Examples.AspNet.Design.SimpleDataListDesigner)), _
     EditorAttribute(GetType(DataListComponentEditor), _
         GetType(ComponentEditor)) _
     > _
    Public Class SimpleDataList
        Inherits DataList
        
        ' Include code that creates a customized
        ' DataList class here.  
         
    End Class
End Namespace

[C#, C++, JScript] No example is available for C#, C++, or JScript. To view a Visual Basic example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Web.UI.Design.WebControls

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

Assembly: System.Design (in System.Design.dll)

See Also

DataListDesigner Members | System.Web.UI.Design.WebControls Namespace | DataList | DataListComponentEditor

Show: