asp.net分页控件AspNetPager的使用,使用传统分页和存储过程分页
来源:互联网 发布:python的三引号 编辑:程序博客网 时间:2024/06/08 06:40
记录一下,分页控件的使用,先记录AspNetPager分页控件的使用
AspNetPager分页的控件的下载地址是:http://www.webdiyer.com/Controls/AspNetPager/Downloads
在线帮助文档:http://www.webdiyer.com/AspNetPagerDocs/index.html
AspNetPager比较重要的几个属性
CurrentPageIndex 获取或设置当前显示页的索引。
PageSize 获取或设置每页显示的项数。
PageCount 获取所有要分页的记录需要的总页数。
CustomInfoHTML 获取或设置在显示在用户自定义信息区的用户自定义HTML文本内容。
FirstPageText 获取或设置为第一页按钮显示的文本。
LastPageText 获取或设置为最后一页按钮显示的文本。
PrevPageText 获取或设置为上一页按钮显示的文本。
RecordCount 获取或设置需要分页的所有记录的总数。
AlwaysShow 获取或设置一个值,该值指定是否总是显示AspNetPager分页按件,即使要分页的数据只有一页。
ShowPageIndex 获取或设置一个值,该值指示是否在页导航元素中显示页索引数值按钮。
ShowPrevNext 获取或设置一个值,该值指示是否在页导航元素中显示上一页和下一页按钮。
UrlPaging 获取或设置是否启用url来传递分页信息。
1.aspnetpager使用传统方式分页
使用Repeater控件和AspNetPager控件实现传统分页,
private void BindRepeater()
{
string sql = "select * from tb_Roles";//自定义的SQL语句
int recordcount;
SqlCommand cmd = new SqlCommand(sql, GetConnection());
cmd.CommandType = CommandType.Text;
SqlDataAdapter ada = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
int startRow = (this.AspNetPager1.CurrentPageIndex - 1) * this.AspNetPager1.PageSize;
ada.Fill(ds, startRow, this.AspNetPager1.PageSize, "table");
recordcount = GetPageRecord(sql);
this.AspNetPager1.RecordCount = recordcount;
this.Repeater1.DataSource = ds;
this.Repeater1.DataBind();
}
另外在AspNetPager分页控件PageChanged事件中绑定。
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
this.BindRepeater();
}
另外获取总记录数的方法
public int GetPageRecord(string sql)
{
sql = System.Text.RegularExpressions.Regex.Replace(sql, "ORDER BY.*", "");
sql = "select count(*) from (" + sql + ") as temp";
SqlCommand cmd = new SqlCommand(sql, GetConnection());
cmd.Connection.Open();
int recordcount = (int)cmd.ExecuteScalar();
cmd.Connection.Close();
return recordcount;
}
2.aspnetpager中使用存储过程分页
调用存储过程获取数据
private void BindListView()
{
this.AspNetPager2.RecordCount = GetPageRecord("select * from tb_Groups");//获取总记录数
SqlCommand cmd = new SqlCommand("pager", GetConnection());
cmd.CommandType = CommandType.StoredProcedure;//使用存储过程
int startRow = (this.AspNetPager2.CurrentPageIndex - 1) * this.AspNetPager2.PageSize;//起始点
int endRow = this.AspNetPager2.CurrentPageIndex * this.AspNetPager2.PageSize;
SqlParameter[] parameters = new SqlParameter[]{
new SqlParameter("@startIndex",startRow),
new SqlParameter("@endIndex",endRow),
new SqlParameter("@docount",'0'),
};
cmd.Parameters.AddRange(parameters);
SqlDataAdapter ada = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
ada.Fill(ds,"table");
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
}
同样需要在PageChanged事件调用绑定方法
最后存储过程的代码是用AspNetPager控件生成的代码,根据向导填入相关信息,就可以生成存储过程的代码
- asp.net分页控件AspNetPager的使用,使用传统分页和存储过程分页
- asp.net分页控件AspNetPager的使用,使用传统分页和存储过程分页
- asp.net 分页控件AspNetPager的使用
- asp.net下Repeater使用 AspNetPager分页控件 不用存储过程 完美实现
- ASP.NET调用Oracle分页存储过程并结合ASPnetpager分页控件 实现分页功能
- asp.net结合aspnetpager使用SQL2005的存储过程分页(转)
- AspNetPager的使用 1 (分页存储过程) AspNetPager 分页2(普通分页)
- AspNetPager分页控件的使用
- AspNetPager分页控件的使用
- AspnetPager分页控件的使用
- AspNetPager分页控件的使用
- AspNetPager分页控件的使用
- AspNetPager分页控件的使用
- AspNetPager分页控件的使用
- AspNetPager分页控件的使用
- AspNetPager分页控件的使用
- AspNetPager分页控件的使用
- AspNetPager分页控件的使用
- Enterprise Library 企业库文章
- Apache web server的一点点东西
- jQuery学习一
- Ext.data.DirectStore中DirectAction的回调函数问题
- 关于Android的nodpi,xhdpi,hdpi,mdpi,ldpi
- asp.net分页控件AspNetPager的使用,使用传统分页和存储过程分页
- Gundam Seed 主题曲 歌词
- linux V4L2编程
- 普华基础软件携全系列云产品亮相云计算大会
- iPhone 获取设备唯一标示
- jQuery技巧大放送 csdn贴
- 关于域名到期删除规则实施的解释
- 给明细表对象加事件
- 风格