This documentation is archived and is not being maintained.

DataGridDesigner Class

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

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


[Visual Basic]
Public Class DataGridDesigner
   Inherits BaseDataListDesigner
public class DataGridDesigner : BaseDataListDesigner
public __gc class DataGridDesigner : public BaseDataListDesigner
public class DataGridDesigner 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.


[Visual Basic] The following code example creates a class named SimpleDataGridDesigner that inherits from the DataGridDesigner class and is meant to be used with a class, named SimpleDataGrid, that derives from the System.Web.UI.WebControls.DataGrid class. The designer class overrides the GetDesignTimeHtml method to customize the CellPadding, BorderWidth, and BorderColor properties when the SimpleDataGrid class renders on design surfaces, such as Visual Studio .NET.

[Visual Basic] 
' Create a class that derives from DataGridDesigner
' that displays the custom SimpleDataGrid control
' on a design surface.
Imports System
Imports System.Design
Imports System.Drawing
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Web.UI.WebControls
Imports System.Web.UI.Design.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 SimpleDataGridDesigner
   Inherits DataGridDesigner
   Private simpleGrid As SimpleDataGrid 

   ' Override the GetDesignTimeHtml method.
   Public Overrides Function GetDesignTimeHtml() As String

      Dim designTimeHtml As String = Nothing      
      ' Check the control's BorderStyle property
      ' to conditionally render design-time HTML.
      If (simpleGrid.BorderStyle = BorderStyle.NotSet) Then

          ' Create variables to hold current property settings.
          Dim oldCellPadding As Integer = simpleGrid.CellPadding
          Dim oldBorderWidth As Unit = simpleGrid.BorderWidth
          Dim oldBorderColor As Color = simpleGrid.BorderColor
          ' Set properties and the design-time HTML.
              simpleGrid.CellPadding = 1
              simpleGrid.BorderWidth = Unit.Pixel(3)
              simpleGrid.BorderColor = Color.Brown
              designTimeHtml = MyBase.GetDesignTimeHtml()
          ' If an exception occurs, call the GetErrorDesignTimeHtml
          ' method.
          Catch ex As Exception
              designTimeHtml = GetErrorDesignTimeHtml(ex)

          ' Return properties to their original settings.
              simpleGrid.CellPadding = oldCellPadding
              simpleGrid.BorderWidth = oldBorderWidth
              simpleGrid.BorderColor = oldBorderColor
          End Try
          designTimeHtml = MyBase.GetDesignTimeHtml()
      End If
      Return designTimeHTML

   End Function 

   ' Write a string to the design surface if an error
   ' occurs while trying to render to the designer.
   Protected Overrides Function GetErrorDesignTimeHtml(exc As Exception) As String
      Return CreatePlaceHolderDesignTimeHtml( _
       "An error occurred while rendering to the designer.")

   End Function

   ' Override the Initialize method to ensure that
   ' only an instance of the SimpleDataGrid class is 
   ' used by this designer class.
   Public Overrides Sub Initialize(component As IComponent)
      Debug.Assert( _
        TypeOf component Is SimpleDataGrid, _
        "SimpleDataGridDesigner::Initialize - Invalid SimpleDataGrid Control")
      simpleGrid = CType(component, SimpleDataGrid)

   End Sub
  End Class 
End Namespace

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

[Visual Basic] 
Imports System
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Imports System.Web.UI.Design.WebControls
Imports System.Windows.Forms.Design

Namespace Examples.AspNet
    ' Associate the SimpleDataGrid class with
    ' its designer with the DesignerAttribute class.
    ' Use the EditorAttribute class to associate
    ' SimpleDataGrid with the DataGridComponentEditor
    ' class.
    <DesignerAttribute( _
        GetType(Examples.AspNet.Design.SimpleDataGridDesigner)), _
     EditorAttribute(GetType(DataGridComponentEditor), _
         GetType(ComponentEditor)) _
    > _
    Public Class SimpleDataGrid
        Inherits DataGrid
        ' Include code here for a customized
        ' DataGrid class.
    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.


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

DataGridDesigner Members | System.Web.UI.Design.WebControls Namespace | DataGrid | DataGridComponentEditor