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控件如何实现分页的效果. 分页分为真分页和假分页. 真分页:控件上一页需要显示多少数据,就从数据库取出并绑定多少数据,每次换页时都 ...
随机推荐
- en_o out1
1● o əʊ ɒ ə ɔː ʌ ʊ: 2● oor ʊə ɔː 3● oo u u: 4● or ɜː ə ɔː 5● oar ore ɔː 6● ow əʊ aʊ ...
- vm options设置
-Dfile.encoding=UTF-8 vmopiton.properties 加入 8A7674
- VC++ 报错:Heap corruption detected
今天在写代码时,发现莫名其妙的错误: std::string strName = L“testtest”; char* pOutString = new char(len + 1); Decrypt( ...
- linux pipes
In Linux, a pipe is implemented using two filedata structures which both point at the same temporary ...
- 若所有的参数皆需要类型转换——请为此采用non-member函数
若所有的参数皆需要类型转换--请为此采用non-member函数 经常使用C++的程序猿(希望更多的程序媛),一般不会同意让classes支持类型转换,至于为什么,请看后续的博客.假如我们设计一个表示 ...
- C#中使用Spire.docx操作Word文档
使用docx一段时间之后,一些地方还是不方便,然后就尝试寻找一种更加简便的方法. 之前有尝试过使用Npoi操作word表格,但是太烦人了,随后放弃,然后发现免费版本的spire不错,并且在莫种程度上比 ...
- Python 数值计算库之-[Pandas](六)
- centos7 mysql的安装
本文记录centos7安装mysql的一些过程与遇到的一些坑 下载mysql的压缩包,直接从官网上面下载,链接:http://dev.mysql.com/downloads/mysql/ 选择 MyS ...
- Linux C:access()时间条件竞争漏洞
access()函数用来检查调用进程是否可以对指定的文件执行某种操作. ================================================================ ...
- sql server 表结构 导出 到excel
SELECT 表名 then d.name else '' end, 表说明 then isnull(f.value,'') else '' end, -- 字段序号 = a.colorder, 字段 ...