使用无限滚动自动分页

Automate pagination with infinite scroll

目前我的程序在到达页面末尾时不做任何自动滚动,但它会在 OnClick 事件发生时进行分页,我在 ASP 中有几个嵌套的中继器,对于 C#这就是我如何通过我的数据集使用 OnClick 事件进行分页:

public void relacion_post_comments()
{
    try
    {
        double cuenta;

        SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConexionBD"].ConnectionString);

        SqlDataAdapter cmd1 = new SqlDataAdapter("select * from vw_Muro_Posts WHERE POST_ESTATUS != '0' ORDER BY cast([POST_FECHA] as datetime) DESC", cnn);

        DataSet ds = new DataSet();
        cmd1.Fill(ds, "vw_Muro_Posts");

        cuenta = ds.Tables[0].Rows.Count;


        PagedDataSource pagedData = new PagedDataSource();
        pagedData.DataSource = ds.Tables[0].DefaultView;
        pagedData.AllowPaging = true;
        pagedData.PageSize = 10;
        pagedData.CurrentPageIndex = PgNum;

        double nuevacuenta = Math.Round(cuenta / pagedData.PageSize);

        if (PgNum < 1)
            lnkAtras.Visible = false;

        else if (PgNum > 0)
            lnkAtras.Visible = true;

        if (PgNum == nuevacuenta)
            lnkAdelante.Visible = false;

        else if (PgNum < nuevacuenta)
            lnkAdelante.Visible = true;

        SqlDataAdapter cmd2 = new SqlDataAdapter("SELECT * FROM vw_Muro_Comments WHERE COMM_ESTATUS != '0' ORDER BY cast([COMM_FECHA] as datetime) DESC", cnn);

        cmd2.Fill(ds, "vw_Muro_Comments");

        //Aqui se hace el join de los dos repeaters
        ds.Relations.Add("myrelation",
        ds.Tables["vw_Muro_Posts"].Columns["POST_ID"],
        ds.Tables["vw_Muro_Comments"].Columns["POST_ID"]);

        var c = ds.Tables.Count;

        Repeater_UsrPosts.DataSource = pagedData;
        Page.DataBind();
        cnn.Close();
    }


    catch (Exception ex)
    {
        clsLog.ReportarError();
    }
}


public int PgNum
{
    get
    {
        if (ViewState["PgNum"] != null)
            return Convert.ToInt32(ViewState["PgNum"]);
        else
            return 0;
    }
    set
    {
        ViewState["PgNum"] = value;
    }

}

 protected void lnkAdelante_Click(object sender, EventArgs e)
{
    PgNum += 1;
}

    protected void lnkAtras_Click(object sender, EventArgs e)
{
    PgNum -= 1;
}

问题是,如何将 OnClick 事件替换为与页面滚动、分辨率大小或与客户端在 C# 中的视图行为相关的任何内容,以便用户没有要进行点击,只需到达页面末尾即可加载数据集的下一页?

****************************** 更新 05/10/17 ********* ************************

我在此页面上找到了部分解决方案:https://www.aspsnippets.com/Articles/Implement-Infinite-Scroll-Endless-Scroll-in-ASPNet-using-jQuery-AJAX.aspx

按照那里的所有步骤,我获得了一个无限滚动的单中继器。尽管我仍在弄清楚如何使用嵌套中继器。

到目前为止,我已经尝试了以下方法,但没有成功显示嵌套中继器的数据:

[WebMethod]
public static string GetCustomers(int pageIndex)
{
    return GetCustomersData(pageIndex).GetXml();
}


public static DataSet GetCustomersData(int pageIndex)
{
    string query = "[sp_pro_MuroPosts_PageWise]";
    SqlCommand cmd = new SqlCommand(query);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@PageIndex", pageIndex);
    cmd.Parameters.AddWithValue("@PageSize", 10);
    cmd.Parameters.Add("@PageCount", SqlDbType.Int, 4).Direction = ParameterDirection.Output;
    return GetData(cmd);
}

private static DataSet GetData(SqlCommand cmd)
{


    cmd.Connection = clsBaseDatos.sqlConexion;
    using (cmd.Connection)
    {
        using (DataSet ds = new DataSet())
        {
            SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConexionBD"].ConnectionString);

            SqlDataAdapter sda = new SqlDataAdapter();
            cmd.Connection = cnn;
            sda.SelectCommand = cmd;
            sda.Fill(ds, "vw_Muro_Posts");

            SqlDataAdapter cmd2 = new SqlDataAdapter("SELECT * FROM vw_Muro_Comments WHERE COMM_ESTATUS != '0' ORDER BY cast([COMM_FECHA] as datetime) DESC", cnn);

            cmd2.Fill(ds, "vw_Muro_Comments");

            //Aqui se hace el join de los dos repeaters
            ds.Relations.Add("myrelation",
            ds.Tables["vw_Muro_Posts"].Columns["POST_ID"],
            ds.Tables["vw_Muro_Comments"].Columns["POST_ID"], false);


            DataTable dt = new DataTable("PageCount");
            dt.Columns.Add("PageCount");
            dt.Rows.Add();
            dt.Rows[0][0] = cmd.Parameters["@PageCount"].Value;
            ds.Tables.Add(dt);

            return ds;
        }
    }
}

来自 aspforums.net 的用户 AnandM 好心地在周末解决了这个问题(具有无限滚动的嵌套中继器),原始的 - 完整 - 答案是 post 在以下 [=16] =]:

http://www.aspforums.net/Threads/105785/Infinite-Scroll-Applied-to-Parent-Repeater-bringing-nested-data/Replies/2#Replies