Skip to content

Commit

Permalink
docs(listbox): update onclientitemsrequested event examples
Browse files Browse the repository at this point in the history
  • Loading branch information
P1l3T0 committed Mar 14, 2024
1 parent 5c2e2f6 commit 268f7d5
Showing 1 changed file with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,36 @@ The event handler receives the following parameter:

1. The instance of the listbox firing the event.

You can use this event to get the number of items inside the ListBox.

````JavaScript
<script type="text/javascript">
function OnClientItemsRequested(sender, eventArgs) {
var listBox = sender;
var listBoxElement = listBox.get_element();

var items = listBox.get_items();
var count = items.get_count();

alert(`There are ${count} items in the ListBox`);
}
</script>
````

Or you could preselect the first item when the control loads initially.

````JavaScript
<script type="text/javascript">
function OnClientItemsRequested(sender, eventArgs) {
alert("There are " + sender.get_items().get_count() + " items.");
}
function OnClientLoad(sender, args) {
sender.__preSelectFirst = sender.get_selectedItems().length === 0;
}

function OnClientItemsRequested(sender, eventArgs) {
if (sender.__preSelectFirst) {
sender.__preSelectFirst = false;
sender.getItem(0).select();
}
}
</script>
````

Expand Down

0 comments on commit 268f7d5

Please sign in to comment.