Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

ObjectDataSourceDesigner Class

Note: This class is new in the .NET Framework version 2.0.

Provides design-time support in a visual designer for the ObjectDataSource Web server control.

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

public class ObjectDataSourceDesigner : DataSourceDesigner
public class ObjectDataSourceDesigner extends DataSourceDesigner
public class ObjectDataSourceDesigner extends DataSourceDesigner

The ObjectDataSource control represents a data source that calls methods of a business object in order to perform the Delete, Insert, Select, and Update database operations.

In a visual designer, when you switch from Source to Design view, the markup source code that describes the ObjectDataSource control is parsed and a design-time version of the control is created on the design surface. When you switch back to Source view, the design-time control is persisted to the markup source code and edited into the markup for the Web page. The ObjectDataSourceDesigner class provides design-time support for the ObjectDataSource control in a visual designer.

The ObjectDataSourceDesigner class members provide the following functionality:

  • The CanConfigure property indicates whether the Configure Data Source wizard can be displayed. The CanRefreshSchema property indicates whether the schema of the associated ObjectDataSource control can be refreshed at design time.

  • The SelectMethod property specifies the method that performs the Select function. The TypeName property specifies the type of the business object that provides the data for the associated control.

  • The GetView method returns a data source view with the specified name. The GetViewNames method returns a list of data source view names for the associated ObjectDataSource control. The RefreshSchema method extracts the metadata for the Select method from the associated business object.

  • The Configure method causes the Configure Data Source wizard to be displayed on the visual designer surface. The PreFilterProperties method removes properties from, adds additional properties to, or shadows properties of the associated control.

The following code example shows how to extend the ObjectDataSourceDesigner class to change the appearance and behavior of controls that are derived from the ObjectDataSource control at design time.

The example derives the MyObjectDataSource control from the ObjectDataSource. The MyObjectDataSource is a copy of the ObjectDataSource control. The example also derives the MyObjectDataSourceDesigner class from the ObjectDataSourceDesigner and applies a DesignerAttribute attribute for the MyObjectDataSourceDesigner on the MyObjectDataSource control.

The MyObjectDataSourceDesigner overrides the PreFilterProperties method to make the NamingContainer property visible in the Properties grid at design time.

The MyObjectDataSourceDesigner overrides the GetDesignTimeHtml method to display the TypeName and SelectMethod properties in a placeholder, in addition to the control type and ID.

using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.Design.WebControls;
using System.Collections;
using System.ComponentModel;
using System.Security.Permissions;

namespace Examples.CS.WebControls.Design
{
    // The MyObjectDataSource is a copy of the ObjectDataSource.
    [AspNetHostingPermission(SecurityAction.Demand, 
        Level = AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, 
        Level = AspNetHostingPermissionLevel.Minimal)]
    [Designer(typeof(Examples.CS.WebControls.Design.
        MyObjectDataSourceDesigner))]
    public class MyObjectDataSource : ObjectDataSource
    {
    } // MyObjectDataSource

    // Derive a designer that inherits from the ObjectDataSourceDesigner.
    [ReflectionPermission(SecurityAction.Demand, Flags=ReflectionPermissionFlag.MemberAccess)]
    public class MyObjectDataSourceDesigner : ObjectDataSourceDesigner
    {
        // Generate the design-time markup.
        public override string GetDesignTimeHtml()
        {
            // Get a reference to the control or a copy of the control.
            MyObjectDataSource myODS = (MyObjectDataSource)ViewControl;

            // Create a placeholder that displays the type of the business 
            // object and the name of the Select method.
            string markup = CreatePlaceHolderDesignTimeHtml(
                 "<b>TypeName</b> \"" + myODS.TypeName + "\"<br />" + 
                 "<b>SelectMethod</b> \"" + myODS.SelectMethod + "\"" );

            return markup;

        } // GetDesignTimeHtml

        // Shadow the control properties with design-time properties.
        protected override void PreFilterProperties(IDictionary properties)
        {
            // Call the base method first.
            base.PreFilterProperties(properties);

            // Make the NamingContainer visible in the Properties grid.
            PropertyDescriptor selectProp =
                (PropertyDescriptor)properties["NamingContainer"];
            properties["NamingContainer"] =
                TypeDescriptor.CreateProperty(selectProp.ComponentType,
                    selectProp, BrowsableAttribute.Yes);
        } // PreFilterProperties

    } // MyObjectDataSourceDesigner
} // Examples.CS.WebControls.Design

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
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.