How to scroll to top of RadListBox

2 posts, 1 answers
  1. Alex
    Alex avatar
    1 posts
    Member since:
    Nov 2019

    Posted 04 Dec 2019 Link to this post

    Hello Telerik,

    I have created a sample project with a RadListBox and a button.

    When the page loads, the list is populated using some query from the Northwind database.

    After scrolling the list at a random item, and pressing the button to reload the list,

    I would like to position the list at the top, not at an arbitrary place in the list.

    This functionality should not depend if I have and item selected or not in the list.

    Thanks,

    Alex

  2. Answer
    Peter Milchev
    Admin
    Peter Milchev avatar
    858 posts

    Posted 10 Dec 2019 Link to this post

    Hello Alex,

    For convenience and better visibility from the community, I am sharing the solution from the official support thread here.

    The RadListBox has scroll persistence which saves the scroll position and restores it before the control is loaded fully on the client-side. 

    Nevertheless, you can set the scrollTop property of the _groupElement to 0 and always have the RadListBox scrolled to the top on page load:

    <telerik:RadListBox ID="Item1ListBox" runat="server"
    			        Height="200px" Width="200px"
    			        RenderMode="Lightweight"
        OnClientLoad="OnClientLoad"
    			        SelectionMode="Single"
    			        Skin="MetroTouch"
    			        ViewStateMode="Enabled">
    </telerik:RadListBox>
    <script>
        function OnClientLoad(sender, args) {
            sender._groupElement.scrollTop = 0;
        }
    </script>

    Regards,
    Peter Milchev
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top