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控件如何实现分页的效果. 分页分为真分页和假分页. 真分页:控件上一页需要显示多少数据,就从数据库取出并绑定多少数据,每次换页时都 ...
随机推荐
- laravel 连接同一服务器上多个数据库操作 、 连接多个不同服务器上的不同数据库操作以及多个数据库操作的事务处理
!注意:标红的要注意区分开 第一步.配置.env文件(同一服务器上多个数据库) DB_CONNECTION=pgsqlDB_HOST=IP(例如:127.0.0.1)DB_PORT=端口号(例如:54 ...
- apache-service的使用
apache service目录设置 设置Apache HTTP Server的文件根目录(DocumentRoot) 安装Apache 时,系统会给定一个缺省的文件根目录 如果你觉得这个网页存在这个 ...
- bzoj3332
题解: 首先只有存在的路有可能有值 然后在存储矩阵的同时对于本来就有边的情况直接存下来这条边的值 然后跑一次最大生成树 在最大生成树的同时就可以求出矩阵的信息. 代码: #include<bit ...
- repeat 中的 continue
repeat a := -; then ShowMessage('') else begin Caption := ''; Continue;//不是立即 向上 返回 执行,要先向下 检查循环条件 是 ...
- JAXP/DOM demo
body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...
- C# 对象不能从 DBNull 转换为其他类型。
原因是被查询的数据库表的查询项有空(什么都没填),补填0后OK.
- fluent nhibernate映射的数值类型问题
fluent nhibernate中,数值类型设置不当,就可能会引发一些意想不到错误. 一.引发映射错误 比如,oracle数据库中,字段ID类型是number,结果用codesmith生成代码,实体 ...
- LeetCode刷题记录(python3)
由于之前对算法题接触不多,因此暂时只做easy和medium难度的题. 看完了<算法(第四版)>后重新开始刷LeetCode了,这次决定按topic来刷题,有一个大致的方向.有些题不止包含 ...
- SpringMVC开发小结
1. 自动封装返回对象为JSON 1).在spring配置文件中添加如下配置: <mvc:annotation-driven> <mvc:message-converters> ...
- windows7所有版本迅雷地址下载集合(含32位和64位) - imsoft.cnblogs
Windows7 SP1旗舰版 32位官方原版下载: ed2k://|file|/cn_windows_7_ultimate_with_sp1_x86_dvd_618763.iso|265187737 ...