2

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
}

2 Answers 2

3

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)

Sign up to request clarification or add additional context in comments.

3 Comments

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
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).
I am getting the same problem, how did you manage to solve this? (The SelectedValue is invalid)
0

download UComponent add-on & upload it to package. there you may create you own customized Data types with the help of this addon ,there no need to code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.