Repeater读取数据并分页
来源:互联网 发布:淘宝店铺免费推广软件 编辑:程序博客网 时间:2024/06/06 05:45
----------控件清单---------
Panel Panel1;
Button Button1;
Button Button2;
Label Label1;
Label Label2;
Label Label3;
Label Label4;
Label Label5;
Repeater Repeater1;
----------------------------------.cs页------------------------------------------
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
this.Label1.Text="1";
this.fill();
}
}
private void fill()
{
int pag=Convert.ToInt32(this.Label1.Text);//设置当前页
SqlConnection con=new SqlConnection("server=.;database=Northwind;uid=sa;pwd=980123;");//实例化连接
SqlDataAdapter sda=new SqlDataAdapter();//建立一个数据适配器对象
sda.SelectCommand=new SqlCommand("select * from Employees",con);//实例化SelectCommand,并用他从数据库读出全部数据
DataSet ds=new DataSet();//定义一个数据集填充
sda.Fill(ds,"name");//使用适配器填充数据集到本地表“name”
PagedDataSource ps=new PagedDataSource();//实例化一个PagedDataSource,这个本来是封装是DATAGRID里面的
ps.DataSource=ds.Tables["name"].DefaultView;//设置他的数据源为ds.Tables["name"].DefaultView数据视图
ps.AllowPaging=true;//允许分页
ps.PageSize=3;//每页显示数量
ps.CurrentPageIndex=pag-1;//当前页码,因为页是从0开始的,所以要减1
this.Button1.Enabled=true;//按钮当前状态
this.Button2.Enabled=true;
this.Label5.Text=ps.PageCount.ToString();
if(pag==1)
{
this.Button1.Enabled=false;//如果当前页是 1 ,上一页按钮不可用
}
if(pag==ps.PageCount)
{
this.Button2.Enabled=false;//如果当前页是最后一页 ,下一页按钮不可用
}
this.Repeater1.DataSource=ps;
this.Repeater1.DataBind();
}
窗体代码
private void Button2_Click(object sender, System.EventArgs e)
{
this.Label1.Text=((Convert.ToInt32(this.Label1.Text)) 1).ToString();
this.fill();
}
private void Button1_Click(object sender, System.EventArgs e)
{
this.Label1.Text=((Convert.ToInt32(this.Label1.Text))-1).ToString();
this.fill();
}
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- Repeater读取数据并分页
- Repeater读取数据并分页
- ASP.NET Repeater绑定数据并实现分页
- Repeater控件实现数据绑定,并实现分页效果
- ASP.NET Repeater绑定数据并实现分页
- ASP.NET Repeater绑定数据并实现分页
- repeater分页显示数据
- DataList和Repeater数据分页
- DataList和Repeater数据分页
- asp.net中使用分页控件,并绑定数据到GridView或Repeater
- JSP实现从mysql读取数据并实现分页功能
- 网页实现从数据库读取数据并简单分页
- Repeater显示数据的例子,带分页
- Repeater简单快速显示,分页数据(转载)
- Repeater之非常好的数据分页
- 利用Repeater控件实现数据分页显示
- 绑定Repeater实现分页获取数据
- 分页Repeater导出数据到Excel
- Asp.net2.0关于Header/title/Metatages/Style操作的一点小技巧
- Asp.net自动返回上次请求页面
- 利用WebClient获取远程数据(仅做备份)
- 通过代码给IIS增加主机头
- 根据自定义字符串来缓存(部分)页面
- Repeater读取数据并分页
- ASP.Net使用缓存技术提高效率
- 使用asp.net进行多关键字查询的例子
- IBatisNet系列-执行存储过程
- .NET正则表达式使用高级技巧之反向引用
- 实现.NET应用程序的自动更新
- ASP.NET无限分类
- .NET下正则表达式应用的四个示例
- Asp.net前后台值的调用