3

This one is probably really simple and I am missing something, I am creating an app dev model for SharePoint online and I currently have a ASP.NET DropDownList that I want to populate with items from within SharePoint.

I have got a list called "currency" within the host web and I have managed to retrieve all of these list items using some JavaScript, I now want to put these list items inside of the ASP.NET dropdown but I cant seem to get it wowrking.

I so far have the following code:


.net dropdown:

<asp:DropDownList ID="currencyDropDown" runat="server" ></asp:DropDownList>

JavaScript:

function successHandler() {
        console.log("Success");
        var listItemInfo = '';
        var listItemEnumerator = collListItem.getEnumerator();
        while (listItemEnumerator.moveNext()) {
            var oListItem = listItemEnumerator.get_current();
            console.log(oListItem.get_item('Title'));
            $("#currencyDropDown").val(oListItem.get_item('Title'));

        }

I have tried a few different solutions to set the dropdown but so far none of them appear to have worked.

I would greatly appreciate any help that I can be given with this issue.

3

You need to create the HTML

<select>
 <option value="volvo">Volvo</option>
 <option value="saab">Saab</option>
 <option value="mercedes">Mercedes</option>
 <option value="audi">Audi</option>
</select>

So you have to append the OPTION DOM elements

| improve this answer | |
  • +1 for putting the "Swedish" brands first ;) – Robert Lindgren Aug 4 '15 at 15:58
  • Singular... Saab Automobile was aquired by Spyker (dutch) and then sold to the chinese – Danny '365CSI' Engelman Aug 4 '15 at 16:12
  • And now they do not exist. Volvo is now Chinese but developed in Sweden ;) – Robert Lindgren Aug 4 '15 at 16:14
  • 1
    Thanks @DannyEngelman this really helped. In the end I put what I was getting from the SharePoint list into an Array and using a for loop appended each item: var array = [oListItem.get_item('Title')]; for (var i = 0; i < array.length; i++) { var option = document.createElement("option"); option.value = array[i]; option.text = array[i]; var select = document.getElementById("currencyDropdown"); select.appendChild(option); – Adam13Hylo Aug 7 '15 at 15:09
  • If the question was answered, please press the Answer button, keeps No-Answers hunters and everyone else on StackOverflow happy. – Danny '365CSI' Engelman Aug 8 '15 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.