我在用户控件里用DataGrid绑定了通过属性接收进来的数据源进行展示,可是不管用DataGrid自带的分页功能还是用分页类PagedDataSource,都不能进行正常分页,总是显示第一页,是什么原因啊?
问题补充:
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="MyWUC.ascx.cs" Inherits="MyWork.WebUserControl.MyWUC" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<div>
<br>
<asp:datagrid id="dgData" runat="server"></asp:datagrid><br>
<asp:button id="btnPrev" Text="上一页" Runat="server"></asp:button> <asp:label id="lblCurrentPage" Runat="server"></asp:label>
<asp:button id="btnNext" Text="下一页" Runat="server"></asp:button></div>
后台是:
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
ViewState["Page"] = 0;
Bind();
}
}
private void Bind()
{
PagedDataSource pds = new PagedDataSource(); //设置分页类
pds.DataSource = userData.DefaultView;
pds.AllowPaging = true;
pds.PageSize = 3;
pds.CurrentPageIndex = Pager;
this.lblCurrentPage.Text = "第 " + (pds.CurrentPageIndex + 1).ToString() + " 页 共 " + pds.PageCount.ToString()+" 页";
SetEnable(pds);
this.dgData.DataSource = this.userData;
this.dgData.DataBind();
}
private void SetEnable(PagedDataSource pds)
{
this.btnPrev.Enabled = true;
this.btnNext.Enabled = true;
if (pds.IsFirstPage)
this.btnPrev.Enabled = false;
if (pds.IsLastPage)
this.btnNext.Enabled = false;
}
private void btnPrev_Click(object sender, System.EventArgs e)
{
Pager--;
Bind();
}
private void btnNext_Click(object sender, System.EventArgs e)
{
Pager++;
Bind();
}
/// <summary>
/// 当前页数
/// </summary>
private int Pager
{
get
{
return (int)ViewState["Page"];
}
set
{
ViewState[&quo