Click here to Skip to main content
15,897,187 members

How is make Infinite scroll or scroll paging with repeater and database ? Platforms is asp.net/c# and db MsSQL server

Hüseyin Ulusoy asked:

Open original thread
Hi,

I want scroll paging on my web page . I'm writing code Asp.net and C# 4.0 for this project. I don't want stored procedure , i want only ado.net connections.



ASP.NET
<asp:repeater ID=NewsRepeater runat="server">
<ItemTemplate>
            <div id="content-bottom">
                <div class="content-bottom-inner">
                    <ul>
                        <li>
                            <h4>
                                <%#DataBinder.Eval(Container.DataItem,"NewsTitle") %></h4>
                        </li>
                        <li>
                            <%#DataBinder.Eval(Container.DataItem,"NewsImg") %>
                        </li>
                        <li>
                            <%#DataBinder.Eval(Container.DataItem,"NewsText") %>
                        </li>
                        <li>
                            <%#DataBinder.Eval(Container.DataItem,"NewsLink") %>
                        </li>
                    </ul>
                </div>
            </div>
        </ItemTemplate>

</asp:repeater>
<script type="text/javascript">
    $(window).scroll(function () {
        if ($(window).scrollTop() == $(document).height() - $(window).height())
        {
            
        
                        $.ajax({
                    type: "POST",
                    url: "Default3.aspx/ItemsGet",
                    data: "{}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: AjaxSucceeded,
                    error: AjaxFailed
                });
             
            function AjaxSucceeded() {
                alert("result.d");
            }
            function AjaxFailed() {
                alert("Failed");
            }
        }
    });</script>


public int CurrentPage
    {
        get
        {
            // look for current page in ViewState
            object o = this.ViewState["_CurrentPage"];
            if (o == null)
                return 0;       // default to showing the first page
            else
                return (int)o;
        }

        set
        {
            this.ViewState["_CurrentPage"] = value;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {

        ItemsGet();
    }
    [WebMethod]
    public void ItemsGet()
    {

        SqlConnection myConnection = new SqlConnection("Data Source=localhost\\sqlexpress;Initial Catalog=db1;Integrated Security=True");
        SqlDataAdapter myCommand = new SqlDataAdapter("SELECT [NewsTitle],[NewsImg] ,[NewsText],[NewsLink] FROM NewsTable ORDER BY id desc", myConnection);
      
        DataSet ds = new DataSet();
       
        myCommand.Fill(ds);
        PagedDataSource objPds = new PagedDataSource();
        objPds.DataSource = ds.Tables[0].DefaultView;
        objPds.AllowPaging = true;
        objPds.PageSize = 3;

        objPds.CurrentPageIndex = CurrentPage;

       

        NewsRepeater.DataSource = objPds;
        NewsRepeater.DataBind();
    }


I'm tryed this code but not working. I want write similar this code , because i use 'where' in sql sentences, so a lot where .

For Example;

If checkbox1 and checkbox2 selected than etc.

C#
[WebMethod]
    public void ItemsGet()
    {
 
        SqlConnection myConnection = new SqlConnection("Data Source=localhost\\sqlexpress;Initial Catalog=db1;Integrated Security=True");
        SqlDataAdapter myCommand = new SqlDataAdapter("SELECT [NewsTitle],[NewsImg] ,[NewsText],[NewsLink] FROM NewsTable where check = @checked and check2 =@checked2 ORDER BY id desc", myConnection);
      
        DataSet ds = new DataSet();
       
        myCommand.Fill(ds);
        PagedDataSource objPds = new PagedDataSource();
        objPds.DataSource = ds.Tables[0].DefaultView;
        objPds.AllowPaging = true;
        objPds.PageSize = 3;
 
        objPds.CurrentPageIndex = CurrentPage;
 
       
 
        NewsRepeater.DataSource = objPds;
        NewsRepeater.DataBind();
    }


How is make this ? Have you got a example project ? Thanks
Tags: C# (C# 4.0), ASP.NET4.0, Scrolling, Paging

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900