读书人

aspnetpager 控件显示分页有关问题

发布时间: 2012-05-08 22:09:41 作者: rapoo

aspnetpager 控件显示分页问题
前台:
<webdiyer:aspnetpager id="AspNetPager1" runat="server" horizontalalign="Center"
onpagechanged="AspNetPager1_PageChanged" UrlPaging="True" FirstPageText="首页"
LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页" CustomInfoStyle=""
EnableUrlRewriting="True" UrlPageIndexName="page" UrlRewritePattern=""
CustomInfoSectionWidth="30%" PageIndexBoxType="DropDownList"
ShowBoxThreshold="2" ShowCustomInfoSection="Left" Width="660px"
TextAfterPageIndexBox=" 页" TextBeforePageIndexBox="跳转至:" AlwaysShow="True"
PageSize="2" >
</webdiyer:aspnetpager>

C#:
ds = new BLL.blogtext().getList(blogid,AspNetPager1.PageSize *(AspNetPager1.CurrentPageIndex - 1),AspNetPager1.PageSize ,"temp1");///这个方法在下面

DataList1.DataSource = ds.Tables["temp1"] ;
AspNetPager1.PageSize = 1; //设置每页显示的记录条数
AspNetPager1.RecordCount = ds.Tables["temp1"].Rows.Count; //得出总的记录条数

DataList1.DataBind(); ;//绑定的数据

AspNetPager1.CustomInfoHTML = " 共 " + AspNetPager1.RecordCount.ToString() + " 篇文章 //显示记录条数
AspNetPager1.CustomInfoHTML += " 当前 <font color=\"red\">" + AspNetPager1.CurrentPageIndex.ToString() + "</font>/" + AspNetPager1.PageCount.ToString() + " 页";//显示当前页/共多少页

DAL:

public DataSet getList(int blogid, int startRecord, int maxRecord, string tableName)
{
string sqltxt = @"select * from blogtext where BlogID=@bi order by Time desc";
SqlConnection cone = new SqlConnection(Dbconnect);
SqlCommand cmd = new SqlCommand(sqltxt, cone);
cmd.Parameters.Add("@bi", SqlDbType.Int, 4);
cmd.Parameters["@bi"].Value = blogid;
SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
try
{
cone.Open();
da.Fill(ds, startRecord, maxRecord, tableName);

}
catch
{
throw;
}
finally
{
cone.Close();

}
return ds;
}

=========================================================
问题是:无论我怎么调那个pagesize的值,都只显示一页的数据,而且总页数只有一页,诚心求教!

[解决办法]
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" CustomInfoSectionWidth="80%"
FirstPageText='首页' InputBoxClass="pagerinput"
LastPageText='尾页' NextPageText='下一页'
OnPageChanging="AspNetPager1_PageChanging" PageSize="2" PrevPageText='上一页'
ShowCustomInfoSection="Left" ShowInputBox="Always" ShowNavigationToolTip="False"
SubmitButtonClass="pagerbtn" SubmitButtonStyle="height:20"
SubmitButtonText='GO' TextAfterInputBox=" "
NumericButtonCount="5" HorizontalAlign="Center">


</webdiyer:AspNetPager>





private void Bind()
{
int pageCount = 0;
int recordCount = 0;
int pager = AspNetPager1.CurrentPageIndex;
int pageSize = AspNetPager1.PageSize;
GridView1.DataSource = ProdInfoBLL.GetProdInfoByConditions(pager, pageSize, ref pageCount, ref recordCount);
GridView1.DataBind();

AspNetPager1.RecordCount = recordCount;
AspNetPager1.CustomInfoHTML = "共<font class='pagerred'>" + AspNetPager1.RecordCount + "</font>条记录";
AspNetPager1.CustomInfoHTML = AspNetPager1.CustomInfoHTML + "    ";
AspNetPager1.CustomInfoHTML = AspNetPager1.CustomInfoHTML + "当前第<font class='pagerred'>" + AspNetPager1.CurrentPageIndex + "/" + AspNetPager1.PageCount + "</font>页";
}



protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
Bind();
}


[解决办法]
因为你绑定数据时只有一条数据,ds = new BLL.blogtext().getList(blogid,AspNetPager1.PageSize *(AspNetPager1.CurrentPageIndex - 1),AspNetPager1.PageSize ,"temp1");///这个绑定有问题。。。
[解决办法]

C# code
//这个事件加了吗?双击AspNetPagerprotected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)  {  AspNetPager1.CurrentPageIndex = e.NewPageIndex;  Bind();  }
[解决办法]
为什么没用状态保持对象viewsate呢?其实这控件很简单的,只是我这没有现成的例子,有时间的话帮你做一个!

读书人网 >asp.net

热点推荐