http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 8990|回复: 5

[教程] 【分布式系统框架教程】-使用分页功能

[复制链接]
发表于 2014-11-27 13:08:55 | 显示全部楼层 |阅读模式
【分布式系统框架教程】-使用分页功能

导读部分



1.【分布式系统框架】教程目录帖http://www.sufeinet.com/thread-10624-1-1.html

教程部分

好了,接着上篇所说,分页功能的使用,其实上篇已经介绍的很详细了,细心的亲可以发现,上篇我所贴出的两表之间的关联查询方法就是带分页功能的,
好了多余的代码我就不贴了,大家可以到上一篇去看一下相关方法。
我呢,没有使用什么分页控件,只是大家交流演示一下如何使用这个功能而已,话不多说,下面直接看下前端代码:
[C#] 纯文本查看 复制代码
public partial class List : System.Web.UI.Page
    {
        LoginUserBLL loginbll = new LoginUserBLL();
        UserBLL userbll = new UserBLL();
        //记录总数
        public int totalcounts = 0;
        //页码大小
        public int pageSize = 3;
        //总页数
        public int totalPage = 0;
        //上一页
        public int previosPgIndex = 1;
        //下一页
        public int nextPgIndex = 1;
        //页数
        public int pgindex = 1;
        public List<LoginUserInfo> ulist = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GetData("");
            }
        }
        public void GetData(string strWhere)
        {
            if (Request["pageIndex"] != null)
            {
                string pageIndex = Request["pageIndex"];
                if (!int.TryParse(pageIndex, out pgindex))
                {
                    return;
                }
            }
            ulist = loginbll.FindListPage(strWhere, pgindex, pageSize, out totalcounts);

            //计算出总页数
            totalPage = (totalcounts + pageSize - 1) / pageSize;
            //计算上一页 页数
            if (pgindex - 1 > 0)
            {
                previosPgIndex = pgindex - 1;
            }
            //计算下一页 页数
            if (pgindex + 1 <= totalPage)
            {
                nextPgIndex = pgindex + 1;
            }
            if (pgindex == totalPage)
            {
                nextPgIndex = pgindex;
            }
        }
        
        protected void btnsearch_Click(object sender, EventArgs e)
        {
            //接收关键字
            string key = RequestHelper.GetStringValue(txtKey.Value.Trim());
            string type =ddltype.Value;
            //拼接查询语句
            string strWhere = "1=1 ";

            if (!string.IsNullOrWhiteSpace(key))
            {
                switch (type)
                {
                    case "1":
                        strWhere += "and UserName like '%" + key + "%' ";
                        break;
                    case "2":
                        strWhere += "and ID=" + key + " ";
                        break;
                }
            }
            //
            GetData(strWhere);
        }
    }

前端HTML:也很简单,我只是用foreach循环了一下:
[HTML] 纯文本查看 复制代码
<form name="fom" id="fom" method="post" action="" runat="server">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td height="30">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td height="62" background="/images/nav04.gif">
                            <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td width="21">
                                        <img src="/images/ico07.gif" width="20" height="18" />
                                    </td>
                                    <td width="538">
                                        搜索
                                        <select id="ddltype" runat="server">
                                            <option value="1">名称</option>
                                            <option value="2">ID</option>
                                        </select>
                                        <input name="txtKey" id="txtKey" type="text" size="12" runat="server"/>
                                        <asp:Button ID="btnsearch" runat="server" CssClass="right-button02" Text="搜索" 
                                            />
                                        <input name="btnadd" id="btnadd" type="button" class="right-button08" value="添加用户" />
                                    </td>
                                    <td width="144" align="left">
                                        <a href="#"> </a>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td>
                <table id="subtree1" style="display: " width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td>
                            <table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td height="20">
                                    </td>
                                </tr>
                                <tr>
                                    <td height="40" class="font42">
                                        <table width="100%" border="0" id="listShow" cellpadding="4" cellspacing="1" bgcolor="#464646"
                                            class="newfont03">
                                            <tr bgcolor="#EEEEEE">
                                            <td width="5%" height="30">ID</td>
                                            <td width="5%">登陆用户名</td>
                                            <td width="5%">登录密码</td>
                                            <td width="5%">用户状态</td>
                                            <td width="5%">注册IP</td> 
                                            <td width="5%">登录类型</td>
                                            <td width="5%">用户名称</td>
                                            <td width="5%">性别</td>
                                            <td width="12%">操作</td>
                                            </tr>
                                            <% if (ulist!=null)
                                               {
                                                   foreach (DistributedModel.User.LoginUserInfo u in ulist)
                                                   {
                                                       DistributedModel.User.UserInfo info = u.GetExData<DistributedModel.User.UserInfo>("UserInfo");
                                                   %>
                                            <tr bgcolor="#FFFFFF">
                                            <td height="30"><%=u.ID%></td>
                                            <td><%=u.UserName%></td>
                                            <td><%=u.UserPwd%></td>
                                            <td><%=u.UserStatus%></td>
                                            <td><%=u.LoginIp%></td>
                                            <td><%=u.LoginType%></td>
                                            <td><%=info.Name%></td>
                                            <td><%=info.GetSex()%></td>
                                            <td><a href="AddUser.aspx?id=<%=u.ID %>">编辑|</a> 
                                               <a href="#" id="<%=u.ID %>" class="del">删除</a></td>
                                                </td>
                                            </tr>
                                            <%}
                                               }%>
                                        </table>
                                    </td>
                                </tr>
                            </table>
                            <table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td height="6">
                                        <img src="../images/spacer.gif" width="1" height="1" />
                                    </td>
                                </tr>
                                <tr>
                                    <td height="33">
                                        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="right-font08">
                                            <tr>
                                                <td width="50%">
                                                    共<span class="right-text09" id="totalcounts"><%=totalcounts %></span>条记录 每页显示<span class="right-text09"
                                                        id="pagesize"><%=pageSize %></span>条记录 | 共<span class="right-text09" id="totalpage"><%=totalPage %></span>
                                                    页 | 第 <span class="right-text09" id="pageIndex"><%=pgindex %></span>页
                                                </td>
                                                <td width="49%" align="right">
                                                    [<a href="list.aspx?pageIndex=1" class="right-font08" id="first">首页</a> | <a href="list.aspx?pageIndex=<%=previosPgIndex %>" id="previous" class="right-font08">
                                                        上一页</a> | <a href="list.aspx?pageIndex=<%=nextPgIndex %>" id="next" class="right-font08">下一页</a> | <a href="list.aspx?pageIndex=<%=totalPage %>" id="end"
                                                            class="right-font08">尾页</a>]
                                                </td>
                                                <td width="1%">
                                                    <table width="20" border="0" cellspacing="0" cellpadding="0">
                                                        <tr>
                                                            <td width="1%">
                                                            </td>
                                                            <td width="87%">
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
                 
    </form>

以上就是分页功能的所有代码了。


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2014-11-27 13:49:08 | 显示全部楼层
真是难得给力的帖子啊。
发表于 2014-11-27 14:40:01 | 显示全部楼层
真是难得给力的帖子啊。
发表于 2015-12-13 22:01:44 | 显示全部楼层
学习学习
回复

使用道具 举报

发表于 2015-12-22 14:42:13 | 显示全部楼层
新手过来学学
发表于 2016-3-4 14:09:27 | 显示全部楼层
分页 没有使用存储过程吗
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-3-29 04:37

© 2014-2021

快速回复 返回顶部 返回列表