Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ListBox in Multiple mode Scroll problem

    Hi,

    I have a ListBix (data bound) and has AutoPostBack activated, so user clicks on an item and it refreshes some other list/table on page.

    All works fine in single select mode. The page is refreshed and the selected items become the first one in a long list that has a scroll bar (it automatically scrolls to it ! which is great...).

    But I need "Multiple" select mode too. In this case after single item is selected (or multiple items) the list does not scroll to any of them, it just refreshes the screen and stay at the top of the list (no scrolling).

    I have tried everything with ASP.NET, with javascript code but no success. (Can you scroll with javascript ?)

    Any help will be appreciated (I am guessing this is a common problem with Listbox + AutoPostBack + Multiple mode in ASP.NET).

    Thanks

  • #2
    New to the CF scene
    Join Date
    Mar 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post OK, I find kind of a solution

    Hi,

    I found a way of doing this, I use this Javascript function below and then call it at page_load of ASP.NET (this is for ListBox1+Multiple+AutoPostBack):

    Function autoscroll()
    {
    var lst = From1.Listbox1
    if ((lst.multiple==true) && (lst.length>0)) {
    if (lst[lst.length-1].selected==true) {
    lst[lst.length-1].selected=true;
    return;
    }
    else {
    lst[lst.length-1].selected=true;
    lst[lst.length-1].selected=false;
    }
    for (var i=0; i< lst.length;++i)
    if (lst.selected==true) {
    lst.selected=true;
    return;
    }
    }}

    (Note that the "lst.selected=true" moves/scrolls the ListBox, also I select and deselect the last item so that the clicked item(s) go to the top of the list.)

    *** One important thing You need to call it in ASP.NET like this:

    Page.RegisterStartUpScript("MyScript","<Script language=javascript defer='true'> autoscroll() </script>")

    ("defer" is very important and also RegisterClientScriptBlock doesn't sometimes work correctly)

  • #3
    New to the CF scene
    Join Date
    May 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hello,

    thx a lot. really useful.

    But 2 questions :

    1. is it really lst.selected=true; or lst[i].selected = true;
    used lst[i].selected = true, and it seems to work ...

    2. what about the "defer" attribute ?
    btw, i used windows.attachEvent("onload", myMethod) instead of registering at the server side ...

    greetings


    Code:
    function /*void*/ MultiListEnsureItemVisible(/*element*/ list)
    {
    	if ( !list || !list.multiple || list.length == 0 ) return;
    
    	var lastItem = list[list.length-1];
    	
    	if (lastItem.selected)
    	{
    		lastItem.selected = true;
    		return;
    	}
    	else
    	{
    		lastItem.selected = true;
    		lastItem.selected = false;
    	}
    
    	for (var i=0; i < list.length; i++)
    	{
    		if (list[i].selected) // or list.selected ?
    		{
    			list[i].selected = true;
    			return;
    		}
    	}
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •