现在要用的是数字分页。用PagedDataSource分页。页返回的DataSourcem则是泛型集合。现在做分页。首页 上一页 下一页 尾页 都没问题。 有一个下拉框,可以选择页数http://192.168.1.1/default.aspx?pn=1&Action=AdminList
查询后的则是
http://192.168.1.1/default.aspx?Pn=1&Action=select&title=&text=&starttime=&endtime=下拉框如何选择性分页?
查询后的则是
http://192.168.1.1/default.aspx?Pn=1&Action=select&title=&text=&starttime=&endtime=下拉框如何选择性分页?
解决方案 »
- rss发布传送图片地址问题
- FreeTextBox 如何绑定后台的内容到前台显示
- frame可以用frameset划分框架,iframe有无办法划分
- SqlCommandBuilder问题
- ________我把一段VB.NET转为C#后一直出错,还请各位前辈看看,谢谢
- 救命啊,上次是SqlDataReader出错,现在改成了DataSet还是出错,到底是什么原因啊????
- 关于ASP.net发布网站的生成DLL问题!
- 是否登录,怎么验证呢? ————————没分了,对不起阿
- 请大家谈谈c/s与b/s的区别,及各自的好处
- ASP.net 调用水晶报表出错%……
- 根据时间字段,查今天之后几天内的数据
- asp.net 模态子窗体与GredView分页
另外分页还是不要用PagedDataSource,没有实际意义,只是样子而已。
你如果知道PageDataSource的实现过程,理解分页的作用,你就不会选择这样做。
public int Pages
{
get { return int.Parse(ViewState["page"].ToString()); }
set { ViewState["page"] = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Pages = 1;
//string no = Request.QueryString["page"];
//Pages = no == null ? 1 : int.Parse(no);
PageShow();
URLPaged();
}
// BindRepeater();
}
public void BindRepeater()
{
BookInfoBll bookbll = new BookInfoBll();
List<BookInfo> list = bookbll.GetAll();
this.rptBook.DataSource = list;
this.rptBook.DataBind();
}
public string GetBookType(int typeID)
{
BookTypeInfoBll typeBll = new BookTypeInfoBll();
BooktypeInfo bookType = new BooktypeInfo();
bookType.BookTypeID = typeID; bookType = typeBll.GetOne(bookType); return bookType.BookTypeName;
}
#region 光棒效果
protected void rptBook_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
HtmlTableRow tr = e.Item.FindControl("tr") as HtmlTableRow;
tr.Attributes.Add("onmouseover", "color=this.style.backgroundColor;this.style.backgroundColor='red'");
tr.Attributes.Add("onmouseout", "this.style.backgroundColor=color");
}
}
#endregion
#region post分页
public void PageShow()
{
PagedDataSource pds = new PagedDataSource();
//为pagedDataSource设置数据源
BookInfoBll bookbll = new BookInfoBll();
pds.DataSource = bookbll.GetAll();
//设置Repeater的数据源为PagedDataSource
this.rptBook.DataSource = pds;
//允许分页
pds.AllowPaging = true;
//设置分页的条数
pds.PageSize = 4;
ViewState["count"] = pds.PageCount;
pds.CurrentPageIndex = Pages - 1;
//得到当前页和总也数
this.lnkup.Enabled = true;
this.lnkDwon.Enabled = true;
if (pds.IsFirstPage)
{
lnkup.Enabled = false;
}
if (pds.IsLastPage)
{
lnkDwon.Enabled = false;
}
this.rptBook.DataBind();
}
//首页
protected void lnkStart_Click(object sender, EventArgs e)
{
Pages = 1;
PageShow();
}
//下一页
protected void lnkup_Click(object sender, EventArgs e)
{
Pages--;
PageShow();
}
//上一页
protected void lnkDwon_Click(object sender, EventArgs e)
{
Pages++;
PageShow();
}
//尾页
protected void lnkLast_Click(object sender, EventArgs e)
{
Pages = int.Parse(ViewState["count"].ToString());
PageShow();
}
#endregion
http://download.csdn.net/detail/guotao0609/3606124
{
get { return int.Parse(ViewState["page"].ToString()); }
set { ViewState["page"] = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Pages = 1;
//string no = Request.QueryString["page"];
//Pages = no == null ? 1 : int.Parse(no);
PageShow();
URLPaged();
}
// BindRepeater();
}
#region post分页
public void PageShow()
{
PagedDataSource pds = new PagedDataSource();
//为pagedDataSource设置数据源
BookInfoBll bookbll = new BookInfoBll();
pds.DataSource = bookbll.GetAll();
//设置Repeater的数据源为PagedDataSource
this.rptBook.DataSource = pds;
//允许分页
pds.AllowPaging = true;
//设置分页的条数
pds.PageSize = 4;
ViewState["count"] = pds.PageCount;
pds.CurrentPageIndex = Pages - 1;
//得到当前页和总也数
this.lnkup.Enabled = true;
this.lnkDwon.Enabled = true;
if (pds.IsFirstPage)
{
lnkup.Enabled = false;
}
if (pds.IsLastPage)
{
lnkDwon.Enabled = false;
}
this.rptBook.DataBind();
}
//首页
protected void lnkStart_Click(object sender, EventArgs e)
{
Pages = 1;
PageShow();
}
//下一页
protected void lnkup_Click(object sender, EventArgs e)
{
Pages--;
PageShow();
}
//上一页
protected void lnkDwon_Click(object sender, EventArgs e)
{
Pages++;
PageShow();
}
//尾页
protected void lnkLast_Click(object sender, EventArgs e)
{
Pages = int.Parse(ViewState["count"].ToString());
PageShow();
}
#endregion
{
Pages = 1;
PageShow();
}
if(this.下拉框.value=="下一页")
{
Pages--;
Pageshow();
}
/// 数据绑定
/// </summary>
private void GetProductList() { List<View_CartSPLB> list = new BusinessDAL().GetList();
string keyword = ""; if (Request.QueryString["keyword"] != null) {
keyword = Request.QueryString["keyword"].ToString();
this.txtKeyWord.Value = keyword;
list = new BusinessDAL().GetList().Where(p => p.ProductName.Contains(keyword) || p.SKUNO.Contains(keyword)).ToList();
}
fenye(anp.PageSize, anp.CurrentPageIndex, list);
} #region 分页
/// <summary>
/// 分页方法
/// </summary>
/// <param name="pagesize">页数</param>
/// <param name="pageIndex">页码</param>
/// <param name="list">数据集合</param>
private void fenye(int pagesize, int pageIndex, List<View_CartSPLB> list) {
PagedDataSource pd = new PagedDataSource();
pd.AllowPaging = true;
pd.PageSize = pagesize;
pd.DataSource = list;
this.anp.RecordCount = list.Count;
if (pageIndex >= pd.PageCount) {
pageIndex = pd.PageCount;
}
if (pageIndex <= 1) {
pageIndex = 1;
}
pd.CurrentPageIndex = pageIndex - 1; //if (list.Count == 0) { // string message = "<span color=#FF3300>没有相关信息,建议您更换搜索条件</span>";
//} this.RepeaterPdList.DataSource = pd;
this.RepeaterPdList.DataBind(); }
#endregion #region 翻页
protected void anp_PageChanged(object sender, EventArgs e) {
GetProductList();
}
#endregion
public void strpage()//分页
{
int id = 1;
if (Request.QueryString["id"] != null)
{
id = Convert.ToInt32(Request.QueryString["id"]);
}
int CurPage;
if (Request.QueryString["Page"] != null)
CurPage = Convert.ToInt32(Request.QueryString["Page"]);
else
CurPage = 1;
DataTable dt = midbll.SelBMidSortDt(Convert.ToInt32(6));//绑定数据
PagedDataSource ps = new PagedDataSource();
ps.DataSource = dt.DefaultView;
ps.AllowPaging = true;
ps.PageSize = 20; //每页数目
this.onepage.Text = ps.PageSize.ToString();
this.allmsg.Text = ps.DataSourceCount.ToString();
ps.CurrentPageIndex = CurPage - 1;
this.allpage.Text = ps.PageCount.ToString();
this.allpage1.Text = ps.PageCount.ToString();
this.nowpage.Text = CurPage.ToString();
this.Repeater1.DataSource = ps;
this.Repeater1.DataBind();
if (!ps.IsFirstPage)
prepage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1) + "&&id=" + Request.QueryString["id"].ToString() + "&&Bigid=" + Request.QueryString["Bigid"].ToString();
if (!ps.IsLastPage)
nextpage.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1) + "&&id=" + Request.QueryString["id"].ToString() + "&&Bigid=" + Request.QueryString["Bigid"].ToString();
}
真够晕的啊!你的 192.168.1.1 谁能访问啊?!如果要修改页号,设置其 CurrentPageIndex 属性就行了。例如你可以将 CurrentPageIndex属性与下拉列表的选择值绑定(而Count等属性不需要绑定,因为它是运行时从DataSource计算出来的),然后在下拉列表值改变时执行 DataBind 即可。可能这个时候你对于 VirtualCount 也是一样需要绑定,然后用一个独立的函数计算那些符合用户查询条件的记录的总记录数,或者给出一个估计数即可。