(部分代码)
前台:<% Import NameSpace="System.Data" %>
<asp:Repeater ID="RepnewInfo" runat="server" OnItemDataBound="RepnewInfo_ItemDataBound">
<HeaderTemplate>
<table bgcolor="#E6ECE6" width="100%" border="0" cellpadding="0" cellspacing="2">
<td width=70% align=center class=font>标 题</td>
<td width=30% align=left class=font>作者</td>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td width="70%"><img src=img/new12.gif /><span class=font><a href="Info.aspx?id=<%# DataBinder.Eval(Container.DataItem,"id") %>">
<%# DataBinder.Eval(Container.DataItem,"Info") %></a></span></td>
<td width=30%><span class=font><%# DataBinder.Eval(Container.DataItem,"writer") %></span></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table></FooterTemplate>
</asp:Repeater>
<table bgcolor="#E6ECE6" width="100%" border="0" cellpadding="0" cellspacing="2" class=font>
<hr class=line />
<tr>
<td align=center><asp:HyperLink ID=hplfirst runat=server>首页</asp:HyperLink></td>
<td align=center><asp:HyperLink ID=hplback runat=server>上一页</asp:HyperLink></td>
<td align=center><asp:HyperLink ID=hplnext runat=server>下一页</asp:HyperLink></td>
<td align=center><asp:HyperLink ID=hplend runat=server>末页</asp:HyperLink></td>
</tr>
</table>后台:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection("server=.;database=Ajax2005;uid=sa;pwd=");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
RepnewInfoDataBind();
}
}
public void RepnewInfoDataBind()
{
SqlCommand comm = new SqlCommand();
comm.CommandText = "select * from NewInfo";
comm.Connection = conn;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = comm;
DataTable dt = new DataTable();
//try
//{
da.Fill(dt);
//创建分页类
PagedDataSource pd = new PagedDataSource();
//填充数据
pd.DataSource = dt.DefaultView;
//允许分页
pd.AllowPaging = true;
//设置每页显示条数
pd.PageSize = 5;
//定义变量用来保存但前索引
int curPage;
//判断页面是否有跳转的请求
if (Request.QueryString["Page"] != null)
curPage = Convert.ToInt32(Request.QueryString["Page"]);
else
curPage = 1;
pd.CurrentPageIndex = curPage - 1;
if (!pd.IsFirstPage)
{////定义"上一页"超级连接的URL为:当前执行页面的虚拟路径,并传递下一页面的索引植
this.hplback.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(curPage-1);
//this.hplend.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + pd.PageCount.ToString();
}
if (!pd.IsLastPage)
{
this.hplnext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(curPage + 1);
//this.hplfirst.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + pd.FirstIndexInPage.ToString(); }
this.RepnewInfo.DataSource = dt;
this.RepnewInfo.DataBind();
//}
//catch { }
//finally { Response.Write("<script>alert('对不起,数据不存在!')</script>");}
}运行后也不报错,就是所有的数据全都取出来了,全都显示了,没有分页效果,大家 帮忙看看啊,解决立刻给分!
前台:<% Import NameSpace="System.Data" %>
<asp:Repeater ID="RepnewInfo" runat="server" OnItemDataBound="RepnewInfo_ItemDataBound">
<HeaderTemplate>
<table bgcolor="#E6ECE6" width="100%" border="0" cellpadding="0" cellspacing="2">
<td width=70% align=center class=font>标 题</td>
<td width=30% align=left class=font>作者</td>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td width="70%"><img src=img/new12.gif /><span class=font><a href="Info.aspx?id=<%# DataBinder.Eval(Container.DataItem,"id") %>">
<%# DataBinder.Eval(Container.DataItem,"Info") %></a></span></td>
<td width=30%><span class=font><%# DataBinder.Eval(Container.DataItem,"writer") %></span></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table></FooterTemplate>
</asp:Repeater>
<table bgcolor="#E6ECE6" width="100%" border="0" cellpadding="0" cellspacing="2" class=font>
<hr class=line />
<tr>
<td align=center><asp:HyperLink ID=hplfirst runat=server>首页</asp:HyperLink></td>
<td align=center><asp:HyperLink ID=hplback runat=server>上一页</asp:HyperLink></td>
<td align=center><asp:HyperLink ID=hplnext runat=server>下一页</asp:HyperLink></td>
<td align=center><asp:HyperLink ID=hplend runat=server>末页</asp:HyperLink></td>
</tr>
</table>后台:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection("server=.;database=Ajax2005;uid=sa;pwd=");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
RepnewInfoDataBind();
}
}
public void RepnewInfoDataBind()
{
SqlCommand comm = new SqlCommand();
comm.CommandText = "select * from NewInfo";
comm.Connection = conn;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = comm;
DataTable dt = new DataTable();
//try
//{
da.Fill(dt);
//创建分页类
PagedDataSource pd = new PagedDataSource();
//填充数据
pd.DataSource = dt.DefaultView;
//允许分页
pd.AllowPaging = true;
//设置每页显示条数
pd.PageSize = 5;
//定义变量用来保存但前索引
int curPage;
//判断页面是否有跳转的请求
if (Request.QueryString["Page"] != null)
curPage = Convert.ToInt32(Request.QueryString["Page"]);
else
curPage = 1;
pd.CurrentPageIndex = curPage - 1;
if (!pd.IsFirstPage)
{////定义"上一页"超级连接的URL为:当前执行页面的虚拟路径,并传递下一页面的索引植
this.hplback.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(curPage-1);
//this.hplend.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + pd.PageCount.ToString();
}
if (!pd.IsLastPage)
{
this.hplnext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(curPage + 1);
//this.hplfirst.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + pd.FirstIndexInPage.ToString(); }
this.RepnewInfo.DataSource = dt;
this.RepnewInfo.DataBind();
//}
//catch { }
//finally { Response.Write("<script>alert('对不起,数据不存在!')</script>");}
}运行后也不报错,就是所有的数据全都取出来了,全都显示了,没有分页效果,大家 帮忙看看啊,解决立刻给分!
解决方案 »
- web中如何在虚线上显示字??跪求各位指点小弟。。。。
- 页面之间传参的问题
- 关于在同一母版页中使用多个CSS文件的最终解决方案!
- 如何使用ASPX服务端程序输出CSS文件引用到<head>标签内?
- sql ASP.NET 怎么比较日期?只比较年月
- asp.net mvc 中使用 kindeditor ,无法正常显示kindeditor
- 有没有办法在一个按钮里实现打开浏览对话框并上传???
- vs2010开发asp.net mvc没有CSS提示吗?
- 请问:如何在点击一个服务器端的按钮后,弹出一个新窗口(注:不用客户端的方法)?
- 怎样用ASP实现一个树菜单
- 我要晕了,这个jmail为什么老是错啊
- 如何提高WEB中生成缩略图的效率
this.RepnewInfo.DataSource = pd