次の方法で共有


DataListDesigner クラス

DataList Web サーバー コントロールのデザイン時の動作を拡張します。

この型のすべてのメンバの一覧については、DataListDesigner メンバ を参照してください。

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

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

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

使用例

[Visual Basic] SimpleDataListDesigner という名前のクラスを DataListDesigner クラスから継承して作成するコードの例を次に示します。このクラスは、 System.Web.UI.WebControls.DataList の派生クラスである SimpleDataList クラスと組み合わせて使用します。また、このコードは、 System.Web.UI.Design.WebControls.GetDesignTimeHtml メソッドをオーバーライドして、コントロールが有効なときに紫色の 5 ポイントの境界線を表示します。このデザイナ クラスは、Visual Studio .NET などのデザイン画面に SimpleDataList クラスを表示します。

 
' 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] System.ComponentModel.DesignerAttribute クラスを使用して、 SimpleDataListDesigner クラスを SimpleDataList クラスに関連付けるコード例を次に示します。

 
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] C#、C++、および JScript のサンプルはありません。Visual Basic のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Web.UI.Design.WebControls

プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: System.Design (System.Design.dll 内)

参照

DataListDesigner メンバ | System.Web.UI.Design.WebControls 名前空間 | DataList | DataListComponentEditor