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查询后所得到表中所有的记录。。。

时间: 2024-09-20 06:41:09

asp.net repeater手写分页实例代码_实用技巧的相关文章

asp.net 无刷新分页实例代码_实用技巧

数据类代码: 复制代码 代码如下: using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data;using System.Data.SqlClient;using System.Collections;using System.Reflection; namespace DAL{    public  class UserManageClass    {  

asp.net StreamReader 创建文件的实例代码_实用技巧

复制代码 代码如下: using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;us

asp.net中文件下载功能的实例代码_实用技巧

复制代码 代码如下: //TransmitFile实现下载protected void Button1_Click(object sender, EventArgs e){ Response.ContentType = "application/x-zip-compressed";Response.AddHeader("Content-Disposition", "attachment;filename=z.zip");string filena

asp.net读取磁盘文件、删除实例代码_实用技巧

复制代码 代码如下:     protected void ReadFile()     //读取文件夹,文件     {         string savePath = @"common";         StringBuilder outstring = new StringBuilder();         string absSavePath = Server.MapPath(savePath);         string[] Directorys = Direct

asp.net 获取图片高度和宽度实例代码_实用技巧

复制代码 代码如下: string path = Server.MapPath("img/1.gif"); System.Drawing.Image image = System.Drawing.Image.FromFile(path); Response.Write("宽:" + image.Width + "<br />"); Response.Write("高:" + image.Height );

Asp.Net获取网站截图的实例代码_实用技巧

复制代码 代码如下: using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace WindowsFormsApplication1{    public partial class Form1 : Form    {    

Asp.net中安全退出时清空Session或Cookie的实例代码_实用技巧

概览: 网站中点击退出,如果仅仅是重定向到登录/出页面,此时在浏览器地址栏中输入登录后的某个页面地址如主页,你会发现不用登录就能访问.这种所谓的退出并不是安全的. 那么怎样做到安全退出呢? 那就是点击退出后清空相应的Session或Cookie. 清空Session的代码: Session.Clear(); Session.Abandon(); 清除Cookie的正确代码(假设Cookie名称为UserInfo): if (Request.Cookies["UserInfo"] !=

.net GridView分页模板的实例代码_实用技巧

复制代码 代码如下: //要在GridView中加入如下属性(前台还是后台看你的习惯了.) //实现分页 AllowPaging="true" //一页数据10行  PageSize="10" // 分页时触发的事件OnPageIndexChanging="gvwDesignationName_PageIndexChanging" //在服务器事件里 protected void gvwDesignationName_PageIndexChang

asp.net实现access数据库分页的方法_实用技巧

asp.net操作access数据库是常见的数据库操作应用,本文就来实例讲解一下asp.net实现access数据库分页的方法.希望对大家的asp.net程序设计能有所帮助. 具体实例代码如下: <divclass="page"id="ctrlRecordPage"> 总<asp:LabelID="Zpage"runat="server"Text="1"></asp:Label