New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

OnClientItemsRequested

The OnClientItemsRequested client-side event occurs after the load-on-demand mechanism has added new items to the listbox.

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.

<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.

<script type="text/javascript">
    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>

See Also

In this article