Position the ListBox scroll bar in Asp.net

Source: Internet
Author: User

 

I encountered the following problem: in case of multiple ListBox selections, the scroll always goes to the top after selectedindexchanged is executed.

 

I used the js method written by updatepanel and jquery in the user control.

Front-end

ListBox

<Asp: listBox id = "lbresearcher" runat = "server" width = "130px" rows = "12" autopostback = "true" <br/> onselectedindexchanged = "lbresearcher_selectedindexchanged" selectionmode = "multiple" tooltip = "click" <br/> cssclass = "uc_lbresearcher"> </ASP: listBox>

JS method:

// The selected position of the scroll bar <br/> function scrollselectedheight (allcount, index) {<br/> // the total height of the scroll bar <br/> var allheight = $ (". uc_lbresearcher ") [0]. scrollheight; <br/> // The Position of the selected item In The Middle Of The ListBox <br/> $ (". uc_lbresearcher "). scrolltop (index/allcount) * allheight-$ (". uc_lbresearcher "). height ()/2); </P> <p >}< br/>

Background code

Protected void lbresearcher_selectedindexchanged (Object sender, eventargs E) <br/> {<br/> /// <br/> // function code to be processed in the background <br/> /// <br/> // locate highly executed foreground js method <br/> scriptmanager. registerstartupscript (this. page, this. page. getType (), "key", "scrollselectedheight ('" + lbresearcher. items. count + "','" + lbresearcher. selectedindex + "');", true); <br/>}

 

I need to improve this method. When selecting a pair, I always locate the first selected item.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.