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
660
Client side selection of the WebDropDown value and updating of the control text.
posted

I must be doing something wrong since for the asp.net DropDownList, I only needed 1 line of code.

ddlX.options[i].selected = true;

 

 

  Converting over to an ig control has been a lot of work.  1st my DropDowns are in a WebDialogWindow that starts off hidden which messes up the z-axis so I run the following:

 

 

 

 

 

function ddlInitialize(sender, args) {

 

 

try

{

sender.behavior.set_zIndex(200000);

}

 

 

catch

(err) {

alert(

'unable to initialize drop down' + err.description);

}

Then, in order to change the current selection I have to run the following routines:

 

 

 

 

 

 

 

 

function ddlClearSelection(ddl) {

 

for (var ix = 0; ix < ddl.get_items().get_length(); ix++) {

 

var item = ddl.get_items().getItem(ix);

 

if (item != null) {

item.unselect();

item.inactivate();

}

}

 

return false;

}

 

 

 

 

 

function ddlSelect(ddl, indx) {

ddlClearSelection(ddl);

ddl.set_selectedItemIndex(indx);

ddl.set_activeItemIndex(indx);

ddl.set_currentValue(ddl.get_items().getItem(indx).get_text(),

true);

ddl.get_items().getItem(indx).select();

ddl.get_items().getItem(indx).activate();

ddl._elements.Input.value = ddl.get_items().getItem(indx).get_text();

}

The markup for one of the WebDropDowns is as follows:

<

 

ig:WebDropDown ID="DropDownListAccountGroup2" runat="server" Width="200px" DropDownAnimationDuration="100" DisplayMode="DropDownList" EnableDropDownAsChild="False">

 

<ClientEvents Initialize="ddlInitialize" />

 

<ClientEvents SelectionChanged="ddlAcctGrpChng2" />

 

</ig:WebDropDown>

Parents
  • 24671
    Suggested Answer
    posted

    Hi,

    If you want to select an item on the client, you need to do:

    dropDown.get_items().getItem(i).select();

    Yep, this won't update the input value or deselect other items. If you want to mark all other items as not selected, you can use this function:

    dropDown.__unselectAllItems();

    I am not sure why you need to change activation. Activation should only be used when the end user browses through the items with mouse and or keyword, and it is mostly useful when multiple selection is enabled.

    Alternatively, you can use the following code:

    dropDown.__singleSelect(null,newItem,oldItem); // this will update the selected item index as well. 

    We will consider adding a function selectItem() to the dropdown client-side class, that will simulate a mouse click on the item. I have created a work item for this functionality, the number is: 24657

    Will let you know when it's done. 

    Thanks,

    Angel 

Reply Children