Scroll to the selecteditem in listbox

2 posts, 0 answers
  1. Richard
    Richard avatar
    26 posts
    Member since:
    Oct 2008

    Posted 04 Aug 2011 Link to this post

    I know there are a couple examples of this but none of them fit my exact situation and I need to solve this problem quickly.  Please help.

    I have a page with a a radwindow that pops up.  Inside the radwindow are a few controls but the ones that come into play are an image button, a combobox and a listbox.  The combobox is filled with a list of many items that can be easily searched using the autofill feature.  The listbox has the same list of items.  Once the user finds the item he is looking for, the user clicks the image button and the list box is supposed to selects the same item and autoscroll to that item so the user can then select multiple items after the selected item.

    I am able to do all of this except have the listbox autoscroll to the item and show it visibly in the list box.

    The code I found that I think is close to what I need uses this javascript:

            Sys.Application.add_load(function (e) {
                var item = $find("lstAllGroups").get_selectedItem();
     
                if (item)
                    item.scrollIntoView();

    The problem I am having is the control called lstAllGroups can't be found and I don't know how to activate the javascript from the code behind.

    If you would be able to supply a complete example of this, I would be grateful.

    RJ
  2. Ivan Zhekov
    Admin
    Ivan Zhekov avatar
    540 posts

    Posted 05 Aug 2011 Link to this post

    Hi Richard,

    If the control can not be found, there are two reasons:

    1) The id you tying to get is the short ClientID. In this case use "<%= somecontrol.ClientID %>" to get the actual ID.
    2) If you are using static CliendID and in this case the control is not yet rendered on the page.

    If the controls is not yet rendered, you may execute the javascript from code behind in some event after control initialization.
    There are various posts on the web how to achieve this.

    Best wishes,
    Ivan Zhekov
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top