Nibble

Usercontrol wrapper will also support Dataeditorsettings

Coming in umbraco Juno, custom settings for your datatype when using the usercontrolwrapper method

How? Also by using the DataEditorSetting attribute and marking a public property with it…

How does this look:

.ascx file:

<%@ Control Language="C#" AutoEventWireup="true" 
    CodeBehind="Demo.ascx.cs" 
    Inherits="UmbracoCreateCustomDatatypeWithWrapper.Demo" %>
 
<asp:DropDownList ID="control" runat="server">
</asp:DropDownList>

.ascx.cs file (code behind)

using System;
using System.Data;
using System.Web;
using System.Web.UI.WebControls;
using umbraco.cms.businesslogic.datatype;
 
 
namespace UmbracoCreateCustomDatatypeWithWrapper
{
    public partial class Demo : 
        System.Web.UI.UserControl,
        umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor  
    {
       
        [DataEditorSetting("Connection string")]
        public string ConnectionString { get; set; }
 
        [DataEditorSetting("Select statement")]
        public string SelectStatement { get; set; }
 
        [DataEditorSetting("Text column")]
        public string TextColumn { get; set; }
 
        [DataEditorSetting("Value column")]
        public string ValueColumn { get; set; }
 
        public string umbracoValue;
 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack)
            {
                //onsave
                value = control.SelectedValue;
            }
            else
            {
                control.DataSource =
                    Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteReader(
                    ConnectionString,
                    CommandType.Text,
                    SelectStatement);
 
                control.DataTextField = TextColumn;
                control.DataValueField = ValueColumn;
                control.DataBind();
 
                control.Items.Insert(0, new ListItem(String.Empty, String.Empty));
 
                control.SelectedIndex = 0;
 
                if (value != null)
                    control.SelectedValue = value.ToString();
            }
        }
 
        public object value
        {
            get
            {
                return umbracoValue;
            }
            set
            {
                umbracoValue = value.ToString();
            }
        }
    }
}

 

The datatype editor (custom settings will be visible after selecting the usercontrol):

image

The datatype in action:

image

2 Comments so far

  1. Lee on December 18th, 2010

    Wow that is awesome! Its going to make it even easier for less technical people to create custom datatypes :) Top work.. Looking forward to Juno

  2. Stefania on May 31st, 2011

    Great! Thanks for sharing this!

Leave a Reply