Assembly: System.Web (in system.web.dll)
The PropertyGridEditorPart provides a generic user interface (UI) that enables users to edit custom properties on WebPart and server controls placed in WebPartZoneBase zones. In contrast, the other EditorPart controls, such as the AppearanceEditorPart and BehaviorEditorPart controls, edit only existing, UI-oriented properties from the WebPart class.
Just as there are tool-oriented zones in the Web Parts control set (for details, see the ToolZone class overview), there are tool-oriented part controls, and each of these must reside in a corresponding type of tool zone. These kind of controls in the Web Parts control set have two distinguishing characteristics:
They are helper controls that enable end users to personalize the controls that form the primary UI of a page in a Web Parts application.
They are visible only in certain page display modes.
The PropertyGridEditorPart control is a special control, and it becomes visible only when a Web page is in edit mode, and when a specific WebPart or server control has been selected by a user for editing. The PropertyGridEditorPart control, like all other EditorPart controls, must reside in an EditorZone zone on the page.
An EditorZone zone can contain only EditorPart controls, and EditorPart controls cannot be placed in any other type of zone.
The PropertyGridEditorPart control provides an editing UI for properties that are marked in the source code with the WebBrowsable attribute (from the WebBrowsableAttribute class). When a property is marked with this attribute, a PropertyGridEditorPart control creates the editing UI based on the type of the property, and uses a PropertyDescriptor object if needed to convert the value in each editing control to the type of the property. You can also add other attributes that help the PropertyGridEditorPart control to display the editing UI. The WebDisplayName attribute (from the WebDisplayNameAttribute class) allows you to specify the text for the label that appears with each control in the editing UI. The WebDescription attribute (from the WebDescriptionAttribute class) allows you to specify a string that appears as a ToolTip for each control in the editing UI.
The controls created to edit properties of various types are listed in the following table.
Control created to edit the property
Int, Float, Unit
DropDownList (contains the list of enumerated values)
The PropertyGridEditorPart class has a Title property, which is used to get or set the visible title text for the control. There is also a protected Display property, which determines whether the control is displayed when the page enters edit mode.
The PropertyGridEditorPart class also has two important methods, ApplyChanges and SyncChanges, which it inherits from the EditorPart class and overrides. The methods are critical because they enable getting and setting the property values between the field values of the editor control and the properties on the WebPart control being edited.
Because the PropertyGridEditorPart control allows you to edit only custom properties, you will need the other EditorPart controls in the Web Parts control set to edit the appearance, layout, and behavior of WebPart controls. The other controls include the BehaviorEditorPart, the LayoutEditorPart, and the AppearanceEditorPart controls. These EditorPart controls should provide most editing features required to edit WebPart controls, but if necessary, you can also create a custom editor control by inheriting from the EditorPart class. For a code example, see the EditorPart class overview topic.
To improve accessibility, the PropertyGridEditorPart control is rendered within a <fieldset> element. The <fieldset> element groups the related set of controls used for editing in the PropertyGridEditorPart control, and it facilitates tabbed navigation among those controls for both visual user agents (such as ordinary Web browsers) and speech-oriented user agents (such as screen-reading software).
The markup rendered by default for this control might not conform to accessibility standards such as the Web Content Accessibility Guidelines 1.0 (WCAG) priority 1 guidelines. For details about accessibility support for this control, see ASP.NET Controls and Accessibility.
The following code example demonstrates how to declare a PropertyGridEditorPart control on a Web page, and enable it to edit several UI properties of a WebPart control. The code example has four parts:
A user control that enables you to change display modes on a Web Parts page.
A Web page that contains an EditorZone control and a PropertyGridEditorPart control, along with a reference to a custom WebPart control.
A class that contains the custom WebPart control.
An explanation of how the example works when you load the page in a browser.
The source code for the user control comes from another topic. For this code example to work, you need to obtain the .ascx file for the user control from the Walkthrough: Changing Display Modes on a Web Parts Page topic, and place the file in the same folder as the .aspx page in this code example.
The second part of the code example is the Web page. It contains a declarative reference to an EditorZone control, with a child <zonetemplate> element that contains a declarative reference to a PropertyGridEditorPart control. The page references the custom WebPart control, using a Register directive for the assembly, and the <aspSample:UserInfoWebPart> element for the control.
The third part of the code example is a custom WebPart class named UserInfoWebPart, which is referenced in the Web page. Notice that the various properties that contain information about a user are all marked with the WebBrowsable attribute. This enables the PropertyGridEditorPart control to provide the UI for editing those properties. The properties are also marked with a WebDisplayName attribute, to specify the text of the label that appears next to each control in the editing UI.
For the code example to run, you must compile this source code. You can compile it explicitly and put the resulting assembly in your Web site's Bin folder or the global assembly cache. Alternatively, you can put the source code in your site's App_Code folder, where it will be dynamically compiled at run time. For a walkthrough that demonstrates how to compile, see Walkthrough: Developing and Using a Custom Server Control.
When you load the page in a browser, select Edit Mode in the Display Mode drop-down list control to switch to edit mode. You can click the verbs menu (the downward arrow) in the title bar of the User Information WebPart control, and click Edit to edit the control. When the editing UI is visible, you can see the PropertyGridEditorPart control. Notice that a control is rendered for each of the properties of the UserInfoWebPart class, based on the type of the property. If you make some changes in the editing UI and click the Apply button, you can use the Display Mode drop-down list to return the page to browse mode and see the full effect of the editing changes.
Windows 98, Windows 2000 SP4, Windows Millennium Edition, 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.