Copied to clipboard

Flag this post as spam?

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


  • David F. Hill 122 posts 242 karma points
    Nov 20, 2009 @ 23:01
    David F. Hill
    0

    Custom DDL DataType prevalues - "text" and "value"

    Hello Umbraco Colleagues:

    I have a User Control containing a DropDownList.  The DDL items come from the prevalues of a custom DataType (type: Dropdown list).

    The UC generates a new content node successfully and is *meant* to assign a value to property

    - but the property value is not being set.

    Here is the relevant code:

    int nodeId = 1074;  //PayrollPeriod Picker Node Id
    Document dataType = new Document(nodeId);
    XPathNodeIterator preValueRootElementIterator = umbraco.library.GetPreValues(nodeId);
    preValueRootElementIterator.MoveNext();
    XPathNodeIterator preValueIterator = preValueRootElementIterator.Current.SelectChildren("preValue", "");
    ListItemCollection DDLItems = new ListItemCollection();

    while (preValueIterator.MoveNext())
    {
        DDLItems.Add(new ListItem(preValueIterator.Current.Value, preValueIterator.Current.GetAttribute("id", "")));
    }

    //Bind data to dropdown list
    DropDownList1.DataSource = DDLItems;
    DropDownList1.DataTextField = "Text";
    DropDownList1.DataValueField = "Value";
    DropDownList1.DataBind();

    I believe the problem is with this part:

    ... preValueIterator.Current.GetAttribute("id", "")

    - but I cannot figure out how to read the "text" and "value" from the prevalues. (It seems the "id" of the prevalue will not work.)

    Can anyone please tell me how to get "text" and "value" from the prevalues?

    Thank you,

    David Hill

    PS: As a bonus, could someone tell me how to iterate through the prevalues of a custom datatype. Assigning DDL items in a loop would be preferable to assigning the DataSource because I would have more control over the items.  Thanks! DfH

  • Masood Afzal 176 posts 522 karma points
    Nov 21, 2009 @ 11:15
    Masood Afzal
    1
    public void BindListWithPrevalues(Node node, ListControl control, string propertyAlias)
    {
    Document document = new Document(node.Id);
    ICollection values = PreValues.GetPreValues(document.getProperty(propertyAlias).PropertyType.DataTypeDefinition.DataType.DataTypeDefinitionId).Values;

    control.Items.Clear();

    control.DataTextField = "Value";
    control.DataValueField = "Id";

    control.DataSource = values;

    control.DataBind();
    }

  • Masood Afzal 176 posts 522 karma points
    Nov 21, 2009 @ 11:28
    Masood Afzal
    0
    using umbraco.cms.businesslogic.datatype;
  • David F. Hill 122 posts 242 karma points
    Nov 21, 2009 @ 22:31
    David F. Hill
    0

    Thank you very much.

    David Hill

Please Sign in or register to post replies

Write your reply to:

Draft