Henrik

Henrik

  • NA
  • 1
  • 0

How to create a generic EditorPart using Databound User Controls?

Jun 10 2010 7:18 AM

Hi
For reasons I don't want to bore you with I need to create a custom EditorPart where I use a number of customized user controls for displaying and editing a number of Properties on a WebPart. However, the annoying part is that I need to use "Dynamic Data" for the data interfacing for the control.
In the WebPart code I add something like :
 
[CustomControlPath("path to the custom control")]
[CustomAttribute("Type", bool)]
public bool IsGreen
{
  get;set;
}
An example can be a bool :

 public partial class BooleanUserControl : System.Web.DynamicData.FieldTemplateUserControl
    {
        /// <summary>
        /// uiCheckBox control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.CheckBox UiCheckBox;
        public override Control DataControl
        {
            get
            {
                return UiCheckBox;
            }
        }
        protected override void OnDataBinding(EventArgs e)
        {
            base.OnDataBinding(e);
            object val = FieldValue;
            if ( val != null)
                UiCheckBox.Checked = (bool) val;
        }
    }


I have another base class for creating the WebParts which overrides the creating of editor parts. However, having Google'd "Dynamic Data" I only find info about binding to databases and not binding to WebPart properties.
So, basically my problem is :
I need to create a generic EditorPart using UserControls with uses Dynamic Data for connecting the WebPart properties to the EditorPart. No knowledge of the WebPart is allowed in the EditorPart code but only permissable using attributes for the properties..
Any ideas, links or code snippets?
/Henrik