程序人生系列之新闻发布系统 我的分页经验
2011-06-19 23:09
357 查看
我的转正任务给部长看了之后,要求做一下真正的分页,而不是用 GridView 自带的分页功能,的确,我也觉得那个不好,那么就做吧,做了就可以转正了,哈哈哈!
---分页----
步骤一:存储过程 create PROCEDURE [dbo].[news_selectByIndex]
@startIndex int ,
@endIndex int
AS
BEGIN
with temptbl as (
SELECT ROW_NUMBER() OVER (ORDER BY id )AS Row,* from news
)
SELECT * FROM temptbl where Row between @startIndex and @endIndex
END
步骤二:在SQLHelper中添加相应的方法
public SqlDataReader ExecuteNewsReader(CommandType cmdType, params SqlParameter[] cmdParms)
{
try
{
conn = GetConn();
string cmdText = "news_selectByIndex";
cmd = new SqlCommand(cmdText,conn);
cmd.CommandType = cmdType;
cmd.Parameters.AddRange(cmdParms);
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
cmd.Parameters.Clear();
return rdr;
}
catch
{
conn.Close();
throw;
}
}
步骤三:在页面中添加 ASPNETPager 控件
页首添加
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<webdiyer:AspNetPager ID="AspNetPager1" CssClass="paginator" CurrentPageButt runat="server" AlwaysShow="True" FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PageSize="8" PrevPageText="上一页" ShowCustomInfoSection="Left" ShowInputBox="Never" CustomInfoTextAlign="Left" LayoutType="Table" >
</webdiyer:AspNetPager>
步骤四:为 ASPNETPager 控件添加 CSS 属性
.paginator
{
font: 12px Arial, Helvetica, sans-serif;
padding: 10px 20px 10px 0;
margin: 0px;
}
.paginator a
{
border: solid 1px #ccc;
color: #0063dc;
cursor: pointer;
text-decoration: none;
}
.paginator a:visited
{
padding: 1px 6px;
border: solid 1px #ddd;
background: #fff;
text-decoration: none;
}
.paginator .cpb
{
border: 1px solid #F50;
font-weight: 700;
color: #F50;
background-color: #ffeee5;
}
.paginator a:hover
{
border: solid 1px #F50;
color: #f60;
text-decoration: none;
}
.paginator a, .paginator a:visited, .paginator .cpb, .paginator a:hover
{
float: left;
height: 16px;
line-height: 16px;
min-width: 10px;
_width: 10px;
margin-right: 5px;
text-align: center;
white-space: nowrap;
font-size: 12px;
font-family: Arial,SimSun;
padding: 0 3px;
}
步骤五:编写页面后台代码
public void BindData()
{
//绑定语句
repNews.DataSource = new SQLHelper().ExecuteNewsReader(CommandType.StoredProcedure,
new SqlParameter("@startIndex", AspNetPager1.StartRecordIndex),
new SqlParameter("@endIndex", AspNetPager1.EndRecordIndex));
repNews.DataBind();
this.AspNetPager1.CustomInfoHTML = string.Format("当前第{0}/{1}页 共{2}条记录 每页{3}条", new object[] { this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageCount, this.AspNetPager1.RecordCount, this.AspNetPager1.PageSize });
}
protected void AspNetPager1_PageChanged(object src, EventArgs e)
{
BindData();
}
然后修改后台代码的各个地方,需要使用 BindDate() 的时候都改过来,例如 Page_Load() 还有删除了新闻分类后等等
---分页----
步骤一:存储过程 create PROCEDURE [dbo].[news_selectByIndex]
@startIndex int ,
@endIndex int
AS
BEGIN
with temptbl as (
SELECT ROW_NUMBER() OVER (ORDER BY id )AS Row,* from news
)
SELECT * FROM temptbl where Row between @startIndex and @endIndex
END
步骤二:在SQLHelper中添加相应的方法
public SqlDataReader ExecuteNewsReader(CommandType cmdType, params SqlParameter[] cmdParms)
{
try
{
conn = GetConn();
string cmdText = "news_selectByIndex";
cmd = new SqlCommand(cmdText,conn);
cmd.CommandType = cmdType;
cmd.Parameters.AddRange(cmdParms);
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
cmd.Parameters.Clear();
return rdr;
}
catch
{
conn.Close();
throw;
}
}
步骤三:在页面中添加 ASPNETPager 控件
页首添加
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<webdiyer:AspNetPager ID="AspNetPager1" CssClass="paginator" CurrentPageButt runat="server" AlwaysShow="True" FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PageSize="8" PrevPageText="上一页" ShowCustomInfoSection="Left" ShowInputBox="Never" CustomInfoTextAlign="Left" LayoutType="Table" >
</webdiyer:AspNetPager>
步骤四:为 ASPNETPager 控件添加 CSS 属性
.paginator
{
font: 12px Arial, Helvetica, sans-serif;
padding: 10px 20px 10px 0;
margin: 0px;
}
.paginator a
{
border: solid 1px #ccc;
color: #0063dc;
cursor: pointer;
text-decoration: none;
}
.paginator a:visited
{
padding: 1px 6px;
border: solid 1px #ddd;
background: #fff;
text-decoration: none;
}
.paginator .cpb
{
border: 1px solid #F50;
font-weight: 700;
color: #F50;
background-color: #ffeee5;
}
.paginator a:hover
{
border: solid 1px #F50;
color: #f60;
text-decoration: none;
}
.paginator a, .paginator a:visited, .paginator .cpb, .paginator a:hover
{
float: left;
height: 16px;
line-height: 16px;
min-width: 10px;
_width: 10px;
margin-right: 5px;
text-align: center;
white-space: nowrap;
font-size: 12px;
font-family: Arial,SimSun;
padding: 0 3px;
}
步骤五:编写页面后台代码
public void BindData()
{
//绑定语句
repNews.DataSource = new SQLHelper().ExecuteNewsReader(CommandType.StoredProcedure,
new SqlParameter("@startIndex", AspNetPager1.StartRecordIndex),
new SqlParameter("@endIndex", AspNetPager1.EndRecordIndex));
repNews.DataBind();
this.AspNetPager1.CustomInfoHTML = string.Format("当前第{0}/{1}页 共{2}条记录 每页{3}条", new object[] { this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageCount, this.AspNetPager1.RecordCount, this.AspNetPager1.PageSize });
}
protected void AspNetPager1_PageChanged(object src, EventArgs e)
{
BindData();
}
然后修改后台代码的各个地方,需要使用 BindDate() 的时候都改过来,例如 Page_Load() 还有删除了新闻分类后等等
相关文章推荐
- 程序人生系列之新闻发布系统 12-17
- 程序人生系列之新闻发布系统 29-35
- 程序人生系列之新闻发布系统 在网站部署经验分享
- 程序人生系列之新闻发布系统 10-11
- 程序人生系列之新闻发布系统 06-09
- 程序人生系列之新闻发布系统 18-28
- 程序人生系列之新闻发布系统 44-62
- 程序人生系列之新闻发布系统 01-05
- “MVC+Nhibernate+Jquery-EasyUI” 信息发布系统 第六篇(图片新闻的添加以及带分页的静态页的生成)
- 牛腩新闻发布系统--分页学习(AspnetPager控件)
- JAVA_WEB项目(结合Servlet+jsp+ckEditor编辑器+jquery easyui技术)实现新闻发布管理系统第四篇:前台首页,新闻分类(体育新闻,科技新闻等),新闻列表分页的实现
- 牛腩新闻发布系统 aspnetpager分页(使用Repeater 分页,使用ajax刷新) DropDownList 插入一个item
- JSP分页c:foreach分页代码以及效果新闻发布系统
- “MVC+Nhibernate+Jquery-EasyUI” 信息发布系统 第六篇(图片新闻的添加以及带分页的静态页的生成)
- 新闻发布系统<分页>
- 【牛腩新闻发布系统】真假分页、动态网页与静态网页、同步与异步定义总结
- 新闻发布系统之浅谈分页技术
- 牛腩新闻发布系统---真分页功能
- 【牛腩新闻发布系统】数据表分页显示——真假分页
- 【牛腩新闻发布系统】——分页其实很简单