1、RepeaterDemo_Page.aspx前台代码

<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table cellspacing="3" cellpadding="3">
<tr>
<th bgcolor="#BBA1E0">表单号</th>
<th bgcolor="#BBA1E0">项目经理</th>
<th bgcolor="#BBA1E0">公司名称</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td ><%#Eval("FormNum") %></td>
<td ><%#Eval("PMName")%></td>
<td ><%#Eval("CompanyName")%></td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr>
<td bgcolor="#BBA1E0"><%#Eval("FormNum") %></td>
<td bgcolor="#BBA1E0"><%#Eval("PMName")%></td>
<td bgcolor="#BBA1E0"><%#Eval("CompanyName")%></td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
<tr><td colspan="3"></td></tr>
</table>
</FooterTemplate>
</asp:Repeater>
<div class="ShowPage-font">
<asp:Label ID="lbl_info" runat="server" Text="第x页,共x页"></asp:Label>
<asp:HyperLink ID="firstPage" runat="server">首页</asp:HyperLink>
<asp:HyperLink ID="lnkUp" runat="server">上一页</asp:HyperLink>
<asp:HyperLink ID="lnkDown" runat="server">下一页</asp:HyperLink>
<asp:HyperLink ID="lastPage" runat="server">尾页</asp:HyperLink>
<asp:Label ID="lblPages" runat="server">跳转到</asp:Label>
<input type="text" runat="server" id="txtPages" style="width:50px" />
<asp:Label ID="lblPage" runat="server" Text="页"></asp:Label>
<asp:Button ID="GoPage" runat="server" Height="21px" Text="GO" onclick="GoPage_Click"/>
</div>
</div>
</form> </body>

2、后台代码

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient; namespace DataSourceDemo
{
public partial class RepeaterDemo_Page : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ShowPage();
} }
public DataTable Bind()
{
string str = "select FormNum,PMNameCompanyName from v_Guru_Product_License_Applied ";
return DbHelper.Instance.CreateDataTable(CommandType.Text, str);
} public void ShowPage()
{
PagedDataSource pds = new PagedDataSource();
pds.DataSource = Bind().DefaultView;
pds.AllowPaging = true;
pds.PageSize = 10;
int currentPage = Convert.ToInt32(Request["page"]);
pds.CurrentPageIndex = currentPage;//设当前页
if (!pds.IsFirstPage)
{
lnkUp.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (currentPage - 1);//上一页
firstPage.NavigateUrl = Request.CurrentExecutionFilePath + "?page=0";//首页 }
if (!pds.IsLastPage)
{
lnkDown.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (currentPage + 1);//下一页
lastPage.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (pds.PageCount - 1);//尾页 }
lbl_info.Text = "第" + (currentPage + 1) + "页,共" + pds.PageCount + "页";
Repeater1.DataSource = pds;
Repeater1.DataBind(); } protected void GoPage_Click(object sender, EventArgs e)//跳转页面
{
if (txtPages.Value == "")
{
Response.Redirect("RepeaterDemo_Page.aspx?page=" + 0);
}
else
{
Response.Redirect("RepeaterDemo_Page.aspx?page=" + (Convert.ToInt32(txtPages.Value) - 1));
}
}
}
}

在跳转时不能再用HyperLink控件,否则页面刷新,没法控制输入TextBox的值。

最新文章

  1. AppCan学习笔记--数据存储及listview简单应用
  2. Mac 系统环境变量配置
  3. 学习NSRulerView
  4. 用CSS画个三角形
  5. GitLab的Gravatar头像服务不可用
  6. Oracle Varchar2长度 及 PHP 长度判断
  7. sqlserver 2008express版本启用混合登陆和sa
  8. PAT 1069. The Black Hole of Numbers (20)
  9. mac下设置命令别名
  10. Netflix公司监控内部安全的开源项目
  11. ios 将图片变成圆形
  12. Android--多线程之Handler 前言
  13. Tcl与Design Compiler (八)——DC的逻辑综合与优化
  14. 免费人脸识别APi
  15. 简单MVC理解与实现
  16. PHP中利用PHPMailer配合QQ邮箱实现发邮件
  17. 获取iframe 内容
  18. 「深度剖析」程序员因为奇葩需求暴打pm,然后被双双开除
  19. 高级Linux运维工程师必备技能(扫盲篇)
  20. tf.expand_dims 来增加维度

热门文章

  1. Vue 学习笔记之 —— 组件(踩了个坑)
  2. vue 在微信中设置动态标题
  3. windows IIS FTP 不支持创建多级目录
  4. 使用JMeter进行http压力测试
  5. Codeforces 1152D DP
  6. &lt;el-table&gt;序号逐次增加,翻页时继续累加,解决翻页时从编号1开始的情况
  7. BCZM : 1.16
  8. nodejs jade 模板 引擎的使用方法
  9. Mybatis枚举转换
  10. 在Vue项目中,添加的背景图片在服务器上不显示,如何处理