博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
无刷新分页
阅读量:6825 次
发布时间:2019-06-26

本文共 3306 字,大约阅读时间需要 11 分钟。

1,前台:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">

<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="show" runat="server" TextMode="MultiLine" style=" height:600px; width:600px;"></asp:TextBox>
    </div>
    </form>
</body>
</html>
2,后台:

using System;

using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;

public partial class test : System.Web.UI.Page

{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            show.Text = server_Side_Processing(20,1);
        }
    }

    /// <summary>
    ///服务器端处理程序到数据库查询数据并生成xml档返回
    /// </summary>
    public string server_Side_Processing(int pageSize, int currentPage)
    {
        StringBuilder resultXML = new StringBuilder();
        string str_xml;
        DataSet ds;
        DataAccess da;
        int i;

        resultXML.Append("<?xml version='1.0' encoding='gb2312'?>");
        resultXML.Append("<ajax-response>\n");
        resultXML.Append("<root>\n");

        try

        {
            if (currentPage == 1)
            {
                str_xml = "select top " + pageSize + " * from tbMicroblog order by MicroblogID desc";
            }
            else
            {
                str_xml = "select top " + pageSize + " * from tbMicroblog  MicroblogID not in (select top " + pageSize * (currentPage - 1) + " * from tbMicroblog order by MicroblogID desc) where order by MicroblogID desc";
            }
            da = new DataAccess();
            ds = da.GetDataSetResult(str_xml, "xml_table");

            if (ds != null)

            {

                for (i = 0; i <pageSize; i++)

                {
                    if (ds.Tables[0].Rows[i]==null)
                    {
                        break;
                    }

                    resultXML.Append("<data>\n");

                    resultXML.Append("\t<MicroblogID>" + ds.Tables[0].Rows[i]["MicroblogID"].ToString() + "</MicroblogID>\n");

                    if (ds.Tables[0].Rows[i]["UserID"].ToString().Trim() != "")

                    {
                        resultXML.Append("\t<UserID>" + HttpUtility.UrlEncodeUnicode(ds.Tables[0].Rows[i]["UserID"].ToString().Trim()) + "</UserID>\n");
                    }
                    else
                    {
                        resultXML.Append("\t<UserID>#</UserID>\n");
                    }

                    if (ds.Tables[0].Rows[i]["Content"].ToString().Trim() != "")

                    {
                        resultXML.Append("\t<Content>" + HttpUtility.UrlEncodeUnicode(ds.Tables[0].Rows[i]["Content"].ToString().Trim()) + "</Content>\n");
                    }
                    else
                    {
                        resultXML.Append("\t<Content>#</Content>\n");
                    }

                    if (ds.Tables[0].Rows[i]["Pubdate"].ToString().Trim() != "")

                    {
                        resultXML.Append("\t<Pubdate>" + HttpUtility.UrlEncodeUnicode(ds.Tables[0].Rows[i]["Pubdate"].ToString().Trim()) + "</Pubdate>\n");
                    }
                    else
                    {
                        resultXML.Append("\t<Pubdate>#</Pubdate>\n");
                    }
                    resultXML.Append("</data>\n");
                }
            }
            else
            {
                //resultXML.Append("<?xml version='1.0' encoding='gb2312'?>");
                //resultXML.Append("<ajax-response>\n");
                //resultXML.Append("<root>\n");
                resultXML.Append("<data>\n");
                resultXML.Append("\t<nodata>" + "No Data !" + "</nodata>\n");
                resultXML.Append("</data>\n");
            }

        }

        catch (Exception e)
        {
            Console.WriteLine("{0} Exception caught.", e);
        }

        resultXML.Append("</root>\n");

        resultXML.Append("</ajax-response>");

        return resultXML.ToString();

    }

}

思路分析:

                    if (ds.Tables[0].Rows[i]==null)

                    {
                        break;
                    }

这里是关键.

 以pageSize个数据单元作为一页(数据段),当数据段的数据单元数目<pageSize时就是最后一页了。

转载于:https://www.cnblogs.com/xgcblog/archive/2011/08/23/2150604.html

你可能感兴趣的文章
Redis 基础、高级特性与性能调优
查看>>
BZT52C15S资料
查看>>
Laravel Telescope入门教程(上)
查看>>
Linux配置ip 及网络问题排查
查看>>
AndroidStudio用Cmake方式编译NDK代码(cmake配置.a库)
查看>>
OSChina 周四乱弹 ——黑丝短裙java程序员同事
查看>>
设置iptables之后不能正常访问ftp解决方法
查看>>
移动端rem布局
查看>>
jsp与iframe跨域访问的一个方法
查看>>
ViewPager + Fragment 取消预加载
查看>>
BigDecimal 02 - 注意事项
查看>>
用js玩桌球游戏
查看>>
maven下运行jetty报错
查看>>
android 配置framework 使应用首选安装在SD卡
查看>>
h5 点击表单 顶部fixed 菜单栏 上移
查看>>
windows 2008 R2 64位系统杀毒软件
查看>>
我的友情链接
查看>>
netty学习笔记
查看>>
更改win7文件类型默认操作
查看>>
我的友情链接
查看>>