黑马程序员_repeater分页实现
来源:互联网 发布:美国地缘政治知乎 编辑:程序博客网 时间:2024/06/11 19:05
using System;
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.Sql;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{ //如果是页面首次加载,执行此方法
this.lblCurrentPage.Text = "1";
dataBind();
}
}
private void dataBind()
{
DataSet ds = getDataSet("select *from tb_test");
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables[0].DefaultView;
pds.AllowPaging = true;
pds.PageSize = 5;
repeater1.DataSource = pds;
pds.CurrentPageIndex=Convert.ToInt32(lblCurrentPage.Text)-1;//PagedDataSource的默认起始页是0,而设置的默认起始页为1;故而-1;
lblCurrentPage.Text =(pds.CurrentPageIndex+1).ToString();//同理,当前页要加1
lblTotal.Text = pds.PageCount.ToString();//获取总的页数
this.pageNext.Enabled = true;
this.pagePri.Enabled = true;
if (pds.CurrentPageIndex < 1)
{
pagePri.Enabled = false;
}
if (pds.CurrentPageIndex== pds.PageCount - 1)
{
pageNext.Enabled = false;
}
repeater1.DataBind();
}
private SqlConnection getConnection()
{
SqlConnection con = new SqlConnection("server=.;database=db_test;uid=sa;pwd=;");
return con;
}
private DataSet getDataSet(string str)
{
DataSet dt = new DataSet();
try
{
using (SqlConnection con = getConnection())
{
con.Open();
using (SqlDataAdapter sda = new SqlDataAdapter(str, con))
{
sda.Fill(dt);
con.Close();
con.Dispose();
return dt;
}
}
}
catch (Exception ee)
{
throw new Exception(ee.ToString());
}
}
private int exeCommmand(string str)
{
try
{
using (SqlConnection con = getConnection())
{
con.Open();
using (SqlCommand cmd= new SqlCommand(str, con))
{
int k = cmd.ExecuteNonQuery();
con.Close();
con.Dispose();
return k;
}
}
}
catch (Exception ee)
{
throw new Exception(ee.ToString());
}
}
protected void btnLogin_Click(object sender, EventArgs e)
{
int k=exeCommmand("insert into tb_test(UserName)values('"+txtUserName.Text+"')");
dataBind();
}
protected void pagePri_Click(object sender, EventArgs e)
{
this.lblCurrentPage.Text = Convert.ToString(Convert.ToInt32(lblCurrentPage.Text) - 1);
dataBind();
}
protected void pageNext_Click(object sender, EventArgs e)
{
this.lblCurrentPage.Text = Convert.ToString(Convert.ToInt32(lblCurrentPage.Text)+1);
dataBind();
}
}
- 黑马程序员_repeater分页实现
- 黑马程序员_repeater数据控件分页
- 黑马程序员_repeater控件研究入门
- 黑马程序员:hibernate分页底层的实现
- 黑马程序员_jsp+oracle分页实现
- 黑马程序员----通过DataList实现可以分页的数据源
- 黑马程序员--分页存储过程
- 黑马程序员_sql语句分页
- 黑马day13 分页思路&实现
- 黑马程序员——day13数据库分页
- 黑马程序员_Oracle 数据库分页功能原理
- 黑马程序员-MD5加密实现
- 黑马程序员 多线程的实现
- 黑马程序员--显示实现接口
- 黑马程序员-------代码实现1
- [黑马程序员]sqlserver三种分页方式比较
- 黑马程序员-.net下多线程的实现
- 黑马程序员——实现字符串反转
- 深入Java虚拟机JVM类加载初始化学习
- 双向链表 , 添加 , 得到上层结构体地址
- I/O学习 --
- UML中的stereotype
- chapter6 Hibernate的关联映射
- 黑马程序员_repeater分页实现
- Redis 起步
- 设计模式解析与实现(C++)之Factory模式
- linxu __setup 宏
- 八款开源 Android 游戏引擎 (巨好的资源)
- C# 获取当前路径方法
- Oracle 字符集的查看和修改
- android:shape的使用
- C++中实现Singleton的正确方法