Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Scroll down to selected item in gridview using javascript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.16k
    Comment on it

    The blog is related to move the position of scroll according to the selected item using javascript:- Consider the following example:- Let's say you have a gridview control and a dropdown above that. If you select any item from dropdown the gridview should move the scroll position according to selected item and display the item inside the div.

    Here i am writing down the snapshot of code:-

    1. <asp:dropdownlist id="drpPanels" runat="server" datasourceid="PanelsDataSource" datatextfield="SubCategoryName" datavaluefield="PanelID" onchange="MoveScrollPosition(this);">
    2. </asp:dropdownlist>
    3. <div id="outerholder" style="float: left">
    4. <asp:gridview id="Gridview1" runat="server">
    5. </asp:gridview>
    6. </div>
    7.  
    8.  
    9. <script type="text/javascript">
    10. function MoveScrollPosition(object) { //object here is object of dropdownlist
    11. var container = document.getElementById("outerholder");
    12. var Cpanel;
    13. if (object.selectedIndex < 10) {
    14. Cpanel = document.getElementById("ctl00&#95;ContentPlaceHolder1&#95;lstPanels&#95;ctl0" + object.selectedIndex + "&#95;pnlMain");
    15. }
    16. else {
    17. Cpanel = document.getElementById("ctl00&#95;ContentPlaceHolder1&#95;lstPanels&#95;ctl" + object.selectedIndex + "&#95;pnlMain");
    18. }
    19. //alert(Cpanel.offsetTop * object.selectedIndex);
    20. container.scrollTop = Cpanel.offsetTop ;
    21. //Object.scrollIntoView(false);
    22. }
    23. </script>

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: