Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tom 713 posts 954 karma points
    Feb 03, 2010 @ 01:36
    Tom
    0

    Custom DataType Dropdownlist UserControl value not set

    Hi All,

    I've created a drop down list usercontrol with it's values set up from a db table. The problem is when i use it as a MemberType property the value in the drop down is not set when the member is saved:

    The user control

     

     

     

    public partial class MemberDomainList : UserControl, IUsercontrolDataEditor

    {

     

     

    protected void Page_Load(object sender, EventArgs e)

    {

     

     

    using (var dc = new AdeptDataContext())

    {

    MemberDomainDropDownList.Items.Add(

     

    "");

    MemberDomainDropDownList.Items.AddRange(dc.MemberDomains.Select(m=>

     

    new ListItem { Value = m.ID.ToString(), Text = m.Name }).ToArray());

    }

     

     

    if (Page.IsPostBack)

    {

     

     

    if (!String.IsNullOrEmpty(MemberDomainDropDownList.SelectedValue))

    {

    umbracoValue =

     

    int.Parse(MemberDomainDropDownList.SelectedValue);

    }

    }

     

     

    if (!Page.IsPostBack)

    {

    MemberDomainDropDownList.SelectedValue = umbracoValue >

     

    0 ? umbracoValue.ToString() : "";

    }

    }

     

     

    public object value

    {

     

     

    get { return umbracoValue; }

     

     

    set

    {

     

     

    int.TryParse(value.ToString(), out umbracoValue);

    }

    }

     

     

    public int umbracoValue;

    }

     

    and in the datatypes section its storage value is integer..

     

    Any help would be awesome.

    Thanks,

    Tom

  • Richard Soeteman 4054 posts 12927 karma points MVP 3x
    Feb 03, 2010 @ 08:40
    Richard Soeteman
    1

    Hi Tom,

    You try to set the value in the page_load event. The new value is probably not assigned in this event. I suggest you use the selected_index changed event of the dropdownlist.

    Cheers,

    Richard

  • Tom 713 posts 954 karma points
    Feb 03, 2010 @ 23:32
    Tom
    0

    Hi Richard,

    thanks so much! perfect answer!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies