不能像datagrid那样简单就分页的
要自己算
不过就是算代码也不多
建议去网上下免费的分页控件用
要自己算
不过就是算代码也不多
建议去网上下免费的分页控件用
解决方案 »
- textbox单击获得焦点触发事件问题
- asp.net 关于Excel导出
- ListView控件ItemDataBound事件中,如果取得绑定的数据呢
- (50分)再问关于B/S系统的客户端打印功能问题,HELP^^^^^^
- aspx页面绑定的一问题
- include 的virtual路径能不能带参数?
- 卡了一下午的问题,上传图片,报错:对路径“D:\FtpUpFile\Web\Photo\40”的访问被拒绝。
- 奇怪,控件由中文变英文的问题?
- 关于利用DSOframer打开TXT的问题
- AdRotator能放置Flash广告吗?
- 小弟 欲得 datagrid 绑定javascript事件 并支持翻页的实例代码----急 急 急
- 怎么我做的网页里任何一个控件一按回车就刷新了?
t_liuxue.aspx
===============================
<%@ Page language="c#" Codebehind="t_liuxue.aspx.cs" AutoEventWireup="false" Inherits="go.t_liuxue" %>
<body>
<form runat="server">
<table width="760" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="160" align="middle" valign="top" bgcolor="#e8e8e8"><div align="center"><FONT face="??ì?"><img src="image/liuxuezhinan/1.gif" width="158" height="133"> <go:t_left id="left_1" runat="server" /></FONT></div></td>
<td align="middle" valign="top" bgcolor="#ffffff"><table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="right"><img src="image/liuxuezhinan/2.gif" width="584" height="76"></td>
</tr>
<tr>
<td align="center"><img src="image/liuxuezhinan/t5.gif" width="550" height="23"></td>
</tr>
<tr>
<td align="center" valign="top"><table width="550" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="5" background="image/waiyuketang/xian.gif"> </td>
<td width="488"><asp:datalist id="score" runat="server">
<ItemTemplate>
<table width="350" border="0" align="center" cellspacing="4">
<tr>
<td width="15"><img src="image/waiyuketang/pic079.gif" width="12" height="11"></td>
<td>
<a href="liuxue.aspx?id=<%# DataBinder.Eval(Container.DataItem,"liu_id")%>&class=<%# DataBinder.Eval(Container.DataItem,"class")%>" target=_blank><%# DataBinder.Eval(Container.DataItem,"biaoti")%></a></td>
</tr>
</table>
</ItemTemplate>
</asp:datalist>
<table cellSpacing="0" cellPadding="0" width="90%" align="center" border="0">
<tr>
<td align="right">共有:
<asp:label id="lblRecordCount" runat="server"></asp:label>条新闻 当前为
<asp:label id="lblCurrentPage" runat="server"></asp:label>/<asp:label id="lblPageCount" runat="server"></asp:label>
页
<asp:LinkButton id="lbnPrevPage" CommandName="prev" OnCommand="Page_OnClick" runat="server">上一页</asp:LinkButton>
<asp:LinkButton id="lbnNextPage" CommandName="next" OnCommand="Page_OnClick" runat="server">下一页</asp:LinkButton></td>
</tr>
</table></td>
<td width="10" background="image/waiyuketang/xian2.gif"> </td>
</tr>
<tr>
<td colspan="3"><img src="image/waiyuketang/t4.gif" width="550" height="23"></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
</form>
</body>
========================================
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;namespace go
{
/// <summary>
/// t_waiyu 的摘要说明。
/// </summary>
public class t_liuxue : System.Web.UI.Page
{
//设定变量:每页记录数,总记录数,总页数,当前页 int PageSize,RecordCount,PageCount,CurrentPage;
SqlConnection sqlconn;
protected System.Web.UI.WebControls.DataList score;
protected System.Web.UI.WebControls.Label lblRecordCount;
protected System.Web.UI.WebControls.Label lblCurrentPage;
protected System.Web.UI.WebControls.LinkButton lbnPrevPage;
protected System.Web.UI.WebControls.LinkButton lbnNextPage;
protected System.Web.UI.WebControls.Label lblPageCount;
private void Page_Load(object sender, System.EventArgs e)
{
PageSize=20;
sqlconn=new SqlConnection(你的数据库连接);
sqlconn.Open();
if (! IsPostBack)
{
ListBind();
CurrentPage=0;
ViewState["PageIndex"]=0;
//计算总共有多少记录
RecordCount = CalculateRecord();
lblRecordCount.Text = RecordCount.ToString();
//计算总共有多少页
PageCount = RecordCount/PageSize+1;
lblPageCount.Text = PageCount.ToString();
ViewState["PageCount"] = PageCount;
}
}
//计算总共有多少条记录
public int CalculateRecord()
{
int intCount;
SqlCommand sqlcomm=new SqlCommand("select count(*) as co from t_liuxue",sqlconn);
SqlDataReader rs=sqlcomm.ExecuteReader();
if(rs.Read())
{
intCount = Int32.Parse(rs["co"].ToString());
}
else
{
intCount = 0;
}
rs.Close();
return intCount;
}
ICollection CreateSource()
{
int StartIndex;
//设定导入的起终地址
StartIndex = CurrentPage*PageSize;
string strSel = "select * from t_liuxue where class=1 order by liu_id desc";
DataSet ds = new DataSet();
SqlDataAdapter MyAdapter = new SqlDataAdapter(strSel,sqlconn);
MyAdapter.Fill(ds,StartIndex,PageSize,"t_liuxue");
return ds.Tables["t_liuxue"].DefaultView;
}
public void ListBind()
{
score.DataSource = CreateSource();
score.DataBind();
lbnNextPage.Enabled = true;
lbnPrevPage.Enabled = true;
if(CurrentPage==(PageCount-1)) lbnNextPage.Enabled = false;
if(CurrentPage==0) lbnPrevPage.Enabled = false;
lblCurrentPage.Text = (CurrentPage+1).ToString();
}
public void Page_OnClick(Object sender,CommandEventArgs e)
{
CurrentPage = (int)ViewState["PageIndex"];
PageCount = (int)ViewState["PageCount"];
string cmd = e.CommandName;
//判断cmd,以判定翻页方向
switch(cmd)
{
case "next":
if(CurrentPage<(PageCount-1)) CurrentPage++;
break;
case "prev":
if(CurrentPage>0) CurrentPage--;
break;
}
ViewState["PageIndex"] = CurrentPage;
ListBind();
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
}
}
有示例还有原代码。
http://www.webdiyer.com