asp.net Repeater使用例子,包括分页
<style type="text/css">
.tab{border-collapse:collapse; margin:0 auto;}
.tab th{ border:#000 solid 1px; line-height:24px;}
.tab td{border:#000 solid 1px; line-height:18px;}
.tab td.no{color:#f00;}
</style>
<table class="tab">
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand" >
<HeaderTemplate>
<tbody>
<tr>
<th>555</th>
<th>666</th>
<th>777</th>
</tr>
</tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem,"SendCentreID") %>
</td>
<td><%# DataBinder.Eval(Container.DataItem,"Mo") %>
</td>
<td><%# DataBinder.Eval(Container.DataItem,"Stat") %>
</td>
<td>
<asp:Button ID="Button3" runat="server" UseSubmitBehavior="true" Text="Button" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"ID") %>' CommandName="ButtonOnClick" />
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr>
<td class="no"><%# DataBinder.Eval(Container.DataItem,"SendCentreID") %>
</td>
<td class="no"><%# DataBinder.Eval(Container.DataItem,"Mo") %>
</td>
<td class="no"><%# DataBinder.Eval(Container.DataItem,"Stat") %>
</td>
<td>
<asp:Button ID="Button3" runat="server" Text="Button" UseSubmitBehavior="true" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"ID") %>' CommandName="ButtonOnClick" />
</td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
<tr>
<td colspan="4">
<asp:LinkButton ID="FirstPage" runat="server" OnClick="FirstPage_OnClick">首页</asp:LinkButton>
<asp:LinkButton ID="UpPage" runat="server" OnClick="UpPage_OnClick">上一页</asp:LinkButton>
第<asp:Label ID="ThisPage" runat="server" Text="1"></asp:Label>页 共<asp:Label ID="AllCountPage" runat="server" Text="1"></asp:Label>页
<asp:LinkButton ID="NextPage" runat="server" OnClick="NextPage_OnClick">下一页</asp:LinkButton>
<asp:LinkButton ID="LastPage" runat="server" OnClick="LastPage_OnClick">末页</asp:LinkButton>
<asp:TextBox ID="CountPage" runat="server"></asp:TextBox>
<asp:LinkButton ID="SetCountPage" runat="server" OnClick="SetCountPage_OnClick">转</asp:LinkButton>
</td>
</tr>
</FooterTemplate>
</asp:Repeater>
</table>
后台代码
public struct PageState
{
/// <summary>
/// 当前页
/// </summary>
public int ThisPage;
/// <summary>
/// 要显示的页数
/// </summary>
public int PageSize;
/// <summary>
/// 总页数
/// </summary>
public int AllPageCount;
/// <summary>
/// 记录数
/// </summary>
public int Counts;
}
protected PageState pagestate;
protected String AdoConn = ConfigurationSettings.AppSettings["XueXunTongConn"];
protected void Page_Load(object sender, EventArgs e)
{
pagestate.PageSize = 16;
pagestate.ThisPage = 1;
if (!Page.IsPostBack)
{
GetData("");
}
}
protected void Page_PreRenderComplete(object sender, EventArgs e)
{
}
/// <summary>
/// 设置当然页数
/// </summary>
/// <param name="Count"></param>
private void SetCount()
{
if (pagestate.ThisPage > pagestate.AllPageCount)
{
pagestate.ThisPage = pagestate.AllPageCount;
}
((Label)Repeater1.Controls[this.Repeater1.Controls.Count - 1].FindControl("ThisPage")).Text = pagestate.ThisPage.ToString();
TextBox TB = (TextBox)Repeater1.Controls[this.Repeater1.Controls.Count - 1].FindControl("CountPage");
TB.Text = pagestate.ThisPage.ToString();
((Label)Repeater1.Controls[this.Repeater1.Controls.Count - 1].FindControl("AllCountPage")).Text = pagestate.AllPageCount.ToString();
}
protected void GetData(String Where)
{
DataSet DS = SQLHelp.PageView("SendCentreMo", "*", pagestate.PageSize, pagestate.ThisPage, ref pagestate.AllPageCount, ref pagestate.Counts, "id", true, Where, "id", false);
Repeater1.DataSource = DS;
Repeater1.DataBind();
SetCount();
}
//转
protected void SetCountPage_OnClick(object sender, EventArgs e)
{
TextBox TB = (TextBox)Repeater1.Controls[this.Repeater1.Controls.Count - 1].FindControl("CountPage");
if (TB.Text == "")
{
return;
}
try
{
pagestate.ThisPage = Int32.Parse(TB.Text);
if (pagestate.ThisPage <= 0)
{
pagestate.ThisPage = 1;
}
}
catch
{
pagestate.ThisPage = 1;
}
GetData("");
}
//首页
protected void FirstPage_OnClick(object sender, EventArgs e)
{
pagestate.ThisPage = 1;
GetData("");
}
//末页
protected void LastPage_OnClick(object sender, EventArgs e)
{
try
{
pagestate.ThisPage = Int32.Parse(((Label)Repeater1.Controls[this.Repeater1.Controls.Count - 1].FindControl("AllCountPage")).Text);
}
catch
{
pagestate.ThisPage = 1;
}
GetData("");
}
//上一页
protected void UpPage_OnClick(object sender, EventArgs e)
{
try
{
pagestate.ThisPage = Int32.Parse(((Label)Repeater1.Controls[this.Repeater1.Controls.Count - 1].FindControl("ThisPage")).Text);
pagestate.ThisPage--;
}
catch
{
pagestate.ThisPage = 1;
}
if (pagestate.ThisPage <= 0)
{
pagestate.ThisPage = 1;
}
GetData("");
}
//下一页
protected void NextPage_OnClick(object sender, EventArgs e)
{
try
{
pagestate.ThisPage = Int32.Parse(((Label)Repeater1.Controls[this.Repeater1.Controls.Count - 1].FindControl("ThisPage")).Text);
pagestate.ThisPage++;
}
catch
{
pagestate.ThisPage = 1;
}
GetData("");
}
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
switch (e.CommandName)
{
case "ButtonOnClick":
int i = Convert.ToInt32(e.CommandArgument);
break;
}
}
asp.net Repeater使用例子,包括分页的更多相关文章
- ASP.NET Repeater控件实现简单分页
早上,有看MSDN,看到了 PagedDataSource 类 http://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.pa ...
- Repeater控件的分页实现
本文讲解Repeater控件与PagedDataSource相结合实现其分页功能.PagedDataSource 类封装那些允许数据源控件(如 DataGrid.GridView)执行分页操作的属性. ...
- 前端使用AngularJS的$resource,后端ASP.NET Web API,实现分页、过滤
在上一篇中实现了增删改查,本篇实现分页和过滤. 本系列包括: 1.前端使用AngularJS的$resource,后端ASP.NET Web API,实现增删改查2.前端使用AngularJS的$re ...
- [ASP.NET]asp.net Repeater控件的使用方法
asp.net Repeater控件的使用方法 -- : 4770人阅读 评论() 收藏 举报 asp.netserveraspdatasetdeletexhtml 今天学习了,Repeater控件 ...
- Asp.Net中的三种分页方式
Asp.Net中的三种分页方式 通常分页有3种方法,分别是asp.net自带的数据显示空间如GridView等自带的分页,第三方分页控件如aspnetpager,存储过程分页等. 第一种:使用Grid ...
- ASP.NET repeater添加序号列的方法
ASP.NET repeater添加序号列的方法 1.<itemtemplate> <tr><td> <%# Container.ItemIndex + 1% ...
- ASP.NET Repeater 控件分页
protected void Page_Load(object sender, EventArgs e) { HttpContext context = HttpContext.Current; co ...
- ASP.NET Zero--14.一个例子(7)商品分类管理-分类搜索及分页
分类搜索实现 1.添加搜索框 打开Index视图,添加一个搜索框,代码如下: ... <div class="portlet light"> <div class ...
- repeater控件实现分页
repeater控件实现排序的方法,今天我再向大家介绍repeater控件如何实现分页的效果. 分页分为真分页和假分页. 真分页:控件上一页需要显示多少数据,就从数据库取出并绑定多少数据,每次换页时都 ...
随机推荐
- SQL Server 数据库获取架构信息
得到数据库存储过程列表: select * from dbo.sysobjects where OBJECTPROPERTY(id, N'IsProcedure') = 1 order by name ...
- Microsoft Jet 数据库引擎 SQL 和 ANSI SQL 的比较
http://westlife063.blog.163.com/blog/static/129942096201052591210384/ Microsoft Jet 数据库引擎 SQL 和 AN ...
- js日期选择并将日期返回文本框
date.js // JavaScript Document var gMonths=new Array("一月","二月","三月",&q ...
- ZooKeeper 之 zkCli.sh客户端的命令使用
zkCli.sh的使用 ZooKeeper服务器简历客户端 ./zkCli.sh -timeout 0 -r -server ip:port ./zkCli.sh -timeout 5000 -ser ...
- OSI七层网络模型与TCP/IP四层模型介绍
目录 OSI七层网络模型与TCP/IP四层模型介绍 1.OSI七层网络模型介绍 2.TCP/IP四层网络模型介绍 3.各层对应的协议 4.OSI七层和TCP/IP四层的区别 5.交换机工作在OSI的哪 ...
- 一起来点React Native——常用组件之TextInput
一.前言 文本输入框,相当于OC中的UITextField,在用法和属性方面,两者都有很大的借鉴之处:通过键盘将文本输入到应用程序的一个基本的组件: 二.TextInput的常见属性 因为TextIn ...
- 触电(by quqi99)
高压电线杆相关的触电方式主要是两种: 一是跨步电压,高压电线落在地面时,如果人恰好在这个范围内步行时,就会从一只脚到跨下再到另一只脚到地形成回路,这叫跨步电压.步子越大,电压越大(以落地点为圆心向外电 ...
- iOS 工程自动化 - OCLint
前言 最近一直在做 iOS 工程自动化方向的事情,所以把自己研究和实践的内容进行记录并分享,希望能给大家一些帮助. 为什么要使用 OCLint 做为一个静态代码分析工具,我们引入 OCLint 的目的 ...
- length()
在MATLAB中: size:获取数组的行数和列数 length:数组长度(即行数或列数中的较大值) numel:元素总数. s=size(A),当只有一个输出参数时,返回一个行向量,该行向量的第一个 ...
- parseConf(配置文件解析器)
/****************************************************************************** * * parseConf(配置文件解析 ...