使用无限滚动自动分页

时间:2017-09-21 21:11:44

标签: c# asp.net pagination repeater

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

<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="../assets/bootstrap-3.3.6-dist/css/bootstrap.css">
</head>
<body>
<?php
    ini_set('display_errors', 1);
    error_reporting(~0);

    $serverName = "localhost";
    $userName = "root";
    $userPassword = "test";
    $dbName = "test";

    $conn = mysqli_connect($serverName,$userName,$userPassword,$dbName);

    $sql = "UPDATE customer_order SET 
            p_name = '".$_POST["p_name"]."' ,
            p_qty = '".$_POST["p_qty"]."' ";

    $query = mysqli_query($conn,$sql);

    if($query) {
     echo "Record update successfully";
     header("Location: http://localhost/supplytest2/admin");
    }

    mysqli_close($conn);
?>
</body>
</html>

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

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

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

通过所有步骤后,我获得了一个无限可滚动的单独转发器。虽然我还在弄清楚如何使用嵌套转发器。

到目前为止,我已经尝试了以下内容,但没有成功显示嵌套转发器的数据:

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;
}

1 个答案:

答案 0 :(得分:0)

来自aspforums.net的用户AnandM在周末有善意解决这个问题(带有无限滚动的嵌套转发器),原始的-full-答案发布在以下帖子中:

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