views:

53

answers:

1

I am trying to create a custom datatype. The intention being a dropdown list. As of right now, I can access the control I created but no properties or values are showing up within it. Just the blank drop down.

public partial class usercontrols_admin_customDataType_CountryDropDown : 
    System.Web.UI.UserControl,
    umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor
{
    public string umbracoValue;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            DataSet ds = new DataSet();

            FormFieldBuilder countries = new FormFieldBuilder();
            ds = countries.GetAllCountries();

            ddCountries.DataSource = ds;
            ddCountries.DataTextField = ds.Tables[0].Columns["DisplayName"].ToString();
            ddCountries.DataValueField = ds.Tables[0].Columns["guiCountryID"].ToString();
            ddCountries.DataBind();
        }
    }

    #region IUsercontrolDataEditor Members

    public object value
    {
        get
        {
            return ddCountries.SelectedValue;
        }
        set
        {
            if (value != null) 
            {
                ddCountries.SelectedValue = value.ToString();
            }
        }
    }

    #endregion
}
+1  A: 

This line:

if (Page.IsPostBack)

Should be:

if (!Page.IsPostBack)

Otherwise the drop down will not be populated until after the form has been submitted (posted back)

Tim Saunders
Made the switch and now I'm getting this error:'ddCountries' has a SelectedValue which is invalid because it does not exist in the list of items.Parameter name: value
JGrimm
This indicates that the string in value does not exist in the ddCountries drop down. Try taking out this portion of code and check that it's working. The drop down should display. Once you're sure the drop down is appearing, check the string that is in value (write to the page or step through the code etc).
Tim Saunders