时间:2016-02-16 00:40 来源: 我爱IT技术网 作者:佚名
欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【asp.net repeater手写分页实例代码】,下面是详细的讲解!
asp.net repeater手写分页实例代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Model;
using System.Data.SqlClient;
using System.Data;
public partial class Test_RepeaterFENYE : System.Web.UI.Page
{
private readonly static CategoryBLL cb=new CategoryBLL();
private readonly static Category_Info cgi=new Category_Info();
int Menu_ID=0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
private void BindData()
{
IList<Category_Info> li=cb.GetAllCategory();
if (li.Count > 0)
{
PagedDataSource pds=new PagedDataSource();
pds.DataSource=li;
pds.AllowPaging=true;
pds.PageSize=2;
int curPage;
if (Request.QueryString["page"] !=null)
{
curPage=Convert.ToInt32(Request.QueryString["page"]);
}
else
{
curPage=1;
}
pds.CurrentPageIndex=curPage - 1;
this.Repeater1.DataSource=pds;
this.Repeater1.DataBind();
this.Label4.Text="";
this.Label4.Text +="<a>共有<font color=red><b>" + li.Count.ToString() + "</b></font>条记录</a> ";
this.Label4.Text +="<a>每页显示<font color=red><b>" + pds.PageSize + "</b></font>条</a> ";
this.Label4.Text +="<a>共<font color=red><b>" + pds.PageCount.ToString() + "</b></font>页</a> ";
this.Label4.Text +="<a>当前第<font color=red><b>" + curPage.ToString() + "</b></font>页</a> ";
if (curPage==1)
{
this.Label4.Text +="<a>首页</a> ";
this.Label4.Text +="<a>上一页</a> ";
}
else
{
//this.Label4.Text +="<a href='wjProduct-1-" + Menu_ID + ".html'>首页</a> ";
//this.Label4.Text +="<a href='wjProduct-" + (curPage - 1).ToString() + "-" + Menu_ID + ".html'>上一页</a> ";
this.Label4.Text +="<a href='RepeaterFENYE.aspx'>首页</a> ";
this.Label4.Text +="<a href='RepeaterFENYE.aspx?page="+(curPage - 1).ToString()+"'>上一页</a> ";
}
if (curPage==pds.PageCount)
{
this.Label4.Text +="<a>下一页</a> ";
this.Label4.Text +="<a>尾页</a> ";
}
else
{
this.Label4.Text +="<a href='RepeaterFENYE.aspx?page=" + (curPage + 1).ToString() + "'>下一页</a> ";
this.Label4.Text +="<a href='RepeaterFENYE.aspx?page=" + pds.PageCount.ToString() + "'>尾页</a> ";
//this.Label4.Text +="<a href='wjProduct-" + (curPage + 1).ToString() + "-" + Menu_ID + ".html'>下一页</a> ";
//this.Label4.Text +="<a href='wjProduct-" + pds.PageCount.ToString() + "-" + Menu_ID + ".html'>尾页</a> ";
}
string HtmlSelectString="<select onchange=\"javascript:window.location=this.value\">";
for (int i=1; i <=pds.PageCount; i++)
{
if (i==curPage)
{
//HtmlSelectString +="<option value=wjProduct-" + i + "-" + Menu_ID + ".html selected>第" + i + "页</option>";
HtmlSelectString +="<option value='RepeaterFENYE.aspx?page=" + i.ToString() +"' selected>第" + i + "页</option>";
}
else
{
//HtmlSelectString +="<option value=wjProduct-" + i + "-" + Menu_ID + ".html>第" + i + "页</option>";
HtmlSelectString +="<option value='RepeaterFENYE.aspx?page=" + i.ToString() + "'>第" + i + "页</option>";
}
}
HtmlSelectString +="</select>";
this.Label4.Text +="<a>" + HtmlSelectString + "</a>";
}
else
{
Label4.Text="没有数据!";
}
}
}
注://注释部分为url rewrite的效果。。。li返回的值为SQL查询后所得到表中所有的记录。。。
关于asp.net repeater手写分页实例代码的用户互动如下:
相关问题:
答: >>详细
相关问题:
答: >>详细
相关问题:
答: >>详细
- 【asp】asp.net url重写浅谈-net-url重写
- 【DataSet】DataSet、DataTable、DataRow区别详解
- 【asp】asp.net 动态添加多个用户控件-net-动态添
- 【ASP】ASP.NET中内嵌页面代码的一个问题-NET-内
- 【As】Asp.net中的页面乱码的问题-sp--pn-ne-et
- 【创建】ASP.NET Web API教程 创建域模型的方法详
- 【Asp】Asp.net 页面调用javascript变量的值-net-
- 【ASP】ASP.NET 5升级后如何删除旧版本的DNX-NET5
- 【404页面】ASP.NET设置404页面返回302HTTP状态码
- 【asp】asp.net开发中常见公共捕获异常方式总结(
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
