Copied to clipboard

Flag this post as spam?

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


  • Garret 68 posts 308 karma points
    Mar 11, 2013 @ 19:51
    Garret
    0

    How to set the value of the dropdownlist datatype

    I'm creating a document in Razor and i would like to know how to set the value of a dropdownlist

    dropdownlist has values:

    prevalue value
    paid   145
    not paid 146

    var doc = Document.MakeNew(DateTime.Now.ToString(), DocumentType.GetByAlias("Order"), author, ordersNode.Id);
    doc.getProperty("paymentStatus").Value = 146; @*146 = not paid*@

    this code doesn't work and google didn't supply me with an answer :(

    Any help?

    Kind regards,

    Garret

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Mar 11, 2013 @ 19:56
    Jan Skovgaard
    0

    Hi Garret

    Seems like you don't save and publish the document.

    Have a look at the documentation here http://our.umbraco.org/documentation/Reference/Management/Documents/ - Go to the section "Creating a Document and setting properties" and have a look at that example.

    Be aware that there is a typo in the last line: umbraco.librarh.UpdateDocumentCache(d.Id); it should read umbraco.library.UpdateDocumentCache(d.Id);

    Hope this helps.

    /Jan

  • Garret 68 posts 308 karma points
    Mar 11, 2013 @ 20:00
    Garret
    0

    Hi Jan,

    My problem isn't the saving the node is created and all values are filled except for the the datatype dropdownlist values.
    But if the above is the correct way of doing it, I must be doing something else wrong:) 

    Tnx for helping out

     

  • SC Digital Services Team 104 posts 171 karma points
    Dec 18, 2013 @ 11:42
    SC Digital Services Team
    0

    Bumping this topic - I'm trying to do something similar!

    How do you use the API to create a page and populate/select an item on drop-downs?

    I've tried looking up the property itself and passing through the key/value of the selected item e.g.

    content.SetValue("myDropDown", keypair);

    and setting the value itself as a string or from the model e.g.

    content.SetValue("myDropDown", "item1"); / content.SetValue("myDropDown", model.selectItem);

    but neither option seems to work. I get the data stored in the umbraco.config file, however, when viewing the created page in Umbraco, the dropdown lists don't show the selected value.

    Any help is appreciated!

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Dec 18, 2013 @ 12:38
    Morten Christensen
    0

    I assume this is about the dropdownlist that comes OOTB with Umbraco. The control that is shown in the editor extends System.Web.UI.WebControls.DropDownList and the value it saves is the SelectedValue of the DropDownList that is rendered in the editor.

    I'm not sure what the model is in your example above, but it should be something like this (the SelectedValue corresponds to the value you set in your PreValues, which is Id, Value - and I believe the Id is the SelectedItem):

    content.SetValue("myDropdownAlias", ddl.SelectedValue);

    Hope this helps,

    - Morten

  • SC Digital Services Team 104 posts 171 karma points
    Dec 18, 2013 @ 13:59
    SC Digital Services Team
    0

    Sounds like the approach I'm taking, although I'm stumped as to get the Id & Value of the item I need.

    I need to set property to a particular string (in this case it's "noindex, nofollow" for our search criteria), so it's just a case of matching this to an item in the dropdownlist defined on the page. I've got this so far, but I still can't get the page to show the selected value when I pass the string to it.

    PropertyType metaRobots = content.ContentType.PropertyTypes.FirstOrDefault(x => x.Alias == "metaRobots");
    int dataTypeDefinitionId = metaRobots.DataTypeDefinitionId;
    IEnumerable<string> prevalues = ds.GetPreValuesByDataTypeId(dataTypeDefinitionId);
    
Please Sign in or register to post replies

Write your reply to:

Draft