protected void Page_Load(object sender, EventArgs e)
{ if (!IsPostBack)
{ ArticleList();
//ClassList();
}
} private void ArticleList()
{//AspNetPager分页控件如何用
Database db = new Database();
DataSet ds = db.GetDataSet("Select * From Article");
Repeater1.DataSource = ds;
Repeater1.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
ArticleList();
} 在上述的DataSet中AspNetPager分页控件如何用。
{ if (!IsPostBack)
{ ArticleList();
//ClassList();
}
} private void ArticleList()
{//AspNetPager分页控件如何用
Database db = new Database();
DataSet ds = db.GetDataSet("Select * From Article");
Repeater1.DataSource = ds;
Repeater1.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
ArticleList();
} 在上述的DataSet中AspNetPager分页控件如何用。
解决方案 »
- 怪问题:用response.redirect("a.aspx?name="+username),这个username只能传2个中文字,3个中文字就出现乱码?
- 如果没有VS,怎么发布网站【急求在线等】
- 根据输入的姓名获取对应的英文/去除编辑器的格式
- 怎么 实现无刷新下拉框 四级联动 没一级的都要求从数据库检索来的!
- 读ini文件问题-仅仅是读,写可以的----急
- [CreateUserWizard]控件的问题
- asp.net初学者的一个问题
- 急:求字体一个
- 请问如何将数据库中日期字段的值转成yyyy-mm-dd格式字符串负值给TextBox?
- JS怎么实现自动分页呢?高手过来看看
- 数据库跟页面显示
- 一个页面数据状态保存的问题
<webdiyer:aspnetpager id="AspNetPager1" runat="server" horizontalalign="Center" onpagechanged="AspNetPager1_PageChanged"
showcustominfosection="Left" width="400px" meta:resourceKey="AspNetPager1" style="font-size:14px" InputBoxStyle="width:19px"
CustomInfoHTML="Page <font color='red'><b>%CurrentPageIndex%</b></font> of %PageCount% Order %StartRecordIndex%-%EndRecordIndex%" ShowNavigationToolTip="True" CustomInfoTextAlign="Center" ShowInputBox="Always" FirstPageText="【首页】" LastPageText="【尾页】" NextPageText="【下页】 " PageSize="3" PrevPageText="【前页】 " UrlPaging="true">
</webdiyer:aspnetpager>后台代码:
protected void Page_Load(object sender, EventArgs e)
{ if (!IsPostBack)
{ ArticleList();
//ClassList();
}
} private void ArticleList()
{//AspNetPager分页控件如何用
Database db = new Database();
Database db = new Database();
DataSet ds = db.GetDataSet("Select * From Article");
DataView dv = ds.Tables[0].DefaultView;
PagedDataSource pds = new PagedDataSource();
AspNetPager1.RecordCount = dv.Count;
pds.DataSource = dv;
pds.AllowPaging = true;
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
pds.PageSize = AspNetPager1.PageSize;
Repeater1.DataSource = pds;
Repeater1.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
ArticleList();
}
<webdiyer:aspnetpager id="AspNetPager1" runat="server" horizontalalign="Center" onpagechanged="AspNetPager1_PageChanged"
showcustominfosection="Left" width="400px" meta:resourceKey="AspNetPager1" style="font-size:14px" InputBoxStyle="width:19px"
CustomInfoHTML="Page <font color='red'><b>%CurrentPageIndex%</b></font> of %PageCount% Order %StartRecordIndex%-%EndRecordIndex%" ShowNavigationToolTip="True" CustomInfoTextAlign="Center" ShowInputBox="Always" FirstPageText="【首页】" LastPageText="【尾页】" NextPageText="【下页】 " PageSize="3" PrevPageText="【前页】 " UrlPaging="true"></webdiyer:aspnetpager>
后台代码:
BaseClass bc = new BaseClass(); protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataListDataBind();
}
}
protected void DataListDataBind()
{
DataSet ds = bc.GetDataSet("select * from [reply] order by replyDate desc", "reply");
DataView dv = ds.Tables[0].DefaultView;
PagedDataSource pds = new PagedDataSource();
AspNetPager1.RecordCount = dv.Count;
pds.DataSource = dv;
pds.AllowPaging = true;
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
pds.PageSize = AspNetPager1.PageSize; this.DataList1.DataSource = pds;
this.DataList1.DataBind(); } protected void AspNetPager1_PageChanged(object src, EventArgs e)
{
DataListDataBind();
}
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
Name:
<asp:Label ID="LName" runat="server" Text='<%# Eval("Name") %>'>
</asp:Label><br />
<br />
</ItemTemplate>
</asp:DataList>
<webdiyer:aspnetpager id="pager1" runat="server" onpagechanged="ChangePage"></webdiyer:aspnetpager>
</div>
</form>
</body>
</html>后置代码:default.aspx.cs using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 cpp114.tools.oledb;
using System.Data.OleDb;
using Wuqi.Webdiyer;public partial class test_Default : System.Web.UI.Page
{
protected OleDbConnection conn = new OleDbConnection();
protected OleDbCommand cmd = new OleDbCommand(); protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
initdb();
conn.Open();
cmd.CommandText = "select count(*) from user";
pager1.RecordCount = (int)cmd.ExecuteScalar();
conn.Close();
BindData();
} }
//初始化连接对象
protected void initdb(){
conn.ConnectionString = oledbtool.myConnStr + Server.MapPath(oledbtool.mydbName);
cmd.Connection = conn;
} //数据绑定
protected void BindData() {
initdb();
OleDbDataAdapter sda = new OleDbDataAdapter("select * from user",conn);
DataSet ds = new DataSet();
sda.Fill(ds, pager1.PageSize * (pager1.CurrentPageIndex - 1), pager1.PageSize, "temptbl");
DataList1.DataSource = ds.Tables["temptbl"];
DataList1.DataBind();
} //翻页事件
protected void ChangePage(object src, PageChangedEventArgs e)
{
pager1.CurrentPageIndex = e.NewPageIndex;
BindData();
} }
/// <summary>
/// AspNetPagerQuerySql
/// </summary>
/// <param name="PageIndex">Index Page</param>
/// <param name="PageSize">Page Size</param>
/// <param name="Sql">Sql String</param>
/// <param name="srTable">TableName</param>
/// <param name="error">errorInfomation</param>
/// <returns>DataSet</returns>
public override DataSet AspNetPagerQuerySql(int PageIndex, int PageSize, string Sql, string srTable, out string error)
{
//throw new Exception("The method or operation is not implemented.");
error = null;
DataSet ds = new DataSet();
com.CommandText = Sql;
sda = new SqlDataAdapter(com);
try
{
sda.Fill(ds,PageIndex*PageSize,PageSize,srTable);
}
catch (Exception e)
{
error = e.Message;
}
return ds;
}
#endregion
楼主:
你写的代码大体上没有错误。不过在ArticleList()函数中要控制一下分页。private void ArticleList()
{
int pageindex = 0;//第几页
if (AspNetPager1.CurrentPageIndex < 1)
{
pageindex = 0;
}
else
{
pageindex = AspNetPager1.CurrentPageIndex - 1;
} int RowCount = 20;//每页显示的数量 //DataTable dt = PagingSearch("earch", "id", "", 20, pageindex, "", "", "id");
//这里我用的是一个分页存储过程。 Repeater1.DataSource = dt;
Repeater1.DataBind(); }你这样试试!!!!!
不要用,找我!!!! 呵呵。
楼主:
你写的代码大体上没有错误。不过在ArticleList()函数中要控制一下分页。private void ArticleList()
{
int pageindex = 0;//第几页
if (AspNetPager1.CurrentPageIndex < 1)
{
pageindex = 0;
}
else
{
pageindex = AspNetPager1.CurrentPageIndex - 1;
} int RowCount = 20;//每页显示的数量 //DataTable dt = PagingSearch("earch", "id", "", 20, pageindex, "", "", "id");
//这里我用的是一个分页存储过程。 Repeater1.DataSource = dt;
Repeater1.DataBind(); }你这样试试!!!!!
不要用,找我!!!! 呵呵。