| 
 【分布式系统框架教程】-使用分页功能 导读部分  
 
  
 教程部分 
 好了,接着上篇所说,分页功能的使用,其实上篇已经介绍的很详细了,细心的亲可以发现,上篇我所贴出的两表之间的关联查询方法就是带分页功能的, 好了多余的代码我就不贴了,大家可以到上一篇去看一下相关方法。 我呢,没有使用什么分页控件,只是大家交流演示一下如何使用这个功能而已,话不多说,下面直接看下前端代码: [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> 
以上就是分页功能的所有代码了。 
 |