Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2700
Finding and Selecting an item
posted

I'm sure that this is a basic function of a dropdownlist but I am finding the CSOM very difficult to get to grips with but they may be down to my lack of knowledge of JavaScript/Ajax but there does seem to be a major lack of any clear documentation or samples.

I have a WebDialogWindow which contains a WebDropDown which is databound.  I click a button on a grid to view the item on the grid using the WDW.  What I want to do is to recover a text field (Name) from a column in the Grid (which I have done) and pre-select this name in the WebDropDown.  Pretty standard stuff...

My code so far from lots of various posts is:-

 

 

 

 

 

var oddlpersonnel = $find('<%=ddlPersonnel.ClientID %>');

 

 

 

var holderName = gridrow.get_cell(1).get_value();

oddlpersonnel.selectItem(holderName,

 

true, true );

Looks correct to me - I also tried set_selectItem just in case I needed the extra set_ but still no luck.  The web page says the object does not support this property or method.  I'm not sure I can call selectItem in this way (passing a string which is the displayed text in the DDL) but this doesn't work anyway.

Any suggestions please before I just revert to a standard asp:DropDownList

Parents
No Data
Reply
  • 8160
    posted

    Hello cmdrew,
    you can use the following javascript to find and select item:


     var ddl = $find('<%=WebDropDown1.ClientID %>');

                //iterate through WebDropDown items
                for (i = 1; i < ddl.get_items().getLength(); i++) {
                    var item = ddl.get_items().getItem(i);

                    //Check if the item has text equal to "Beverages"
                    //You can use item.get_value() to check values
                    if (item.get_text() == "Beverages") {
                        //select item
                        item.select();
                    }
                }

    I hope that this helps

Children
No Data