Asp.net mvc dropdownlist add items on scrolling

放肆的年华 提交于 2019-12-21 02:56:12

问题


I am looking for asp.net mvc dropdown list which can adds records if scrollbar is scrolled. I am completely beginner to this area. Could some one guide me on how to implement this or any reusable code such as

Scroll event takes to controller,get records and append to dropdown last item. I think any suggestion could make me understand how to deal with code logic

Here is what I tried to append to dropdown

<select>
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    <option>6</option>
    <option>7</option>
    <option>8</option>
    <option>9</option>
    <option>10</option>
    <option>11</option>
</select>

回答1:


Jquery Code

Below is the Code for using ajax call to controller and get records then bind into to dropdown

var mySelect = $('#mySelect');
 var sIndex = 11, offSet = 10, isPreviousEventComplete = true, isDataAvailable = true;

    mySelect.scroll(function (e) {
   if($(this).scrollTop() + $(this).innerHeight()>=$(this)[0].scrollHeight)
   {   
       var scrollto=$(this).scrollTop();
       if (isPreviousEventComplete && isDataAvailable) {       
          isPreviousEventComplete = false;
        $(".LoaderImage").css("display", "block");

        $.ajax({
          type: "GET",
          url: 'Your url',
          success: function (result) {
                   $.each(result, function(val, text) {            
    mySelect.append(
        $('<option></option>').val(val).html(text)
    );
        });
           mySelect.scrollTop( scrollto );

            isPreviousEventComplete = true;

            if (result == '') //When data is not available
                isDataAvailable = false;

            $(".LoaderImage").css("display", "none");
          },
          error: function (error) {
              alert(error);
          }
        });


      }
               }
    });

Click Demo Link http://jsfiddle.net/sethuramanP/4pmKf/3/ example for add static data to dropdown whenever scroll comes end




回答2:


You can also try this JQuery Select which will support infinite scroll of results.



来源:https://stackoverflow.com/questions/21302989/asp-net-mvc-dropdownlist-add-items-on-scrolling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!