日期:2014-05-18  浏览次数:21095 次

.net datalist分页问题,设置了allowPaging=true,pagesize也设置了但是所有的数据还是在一个页面显示,求助
前台代码:<div 
  当前页码为:<asp:Label ID="Label1" runat="server" Text="1"></asp:Label>
  &nbsp;总页码为:<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
  <asp:LinkButton ID="LinkButtonFirst" runat="server" 
  onclientclick="LinkButtonFirst_Click" onclick="LinkButtonFirst_Click">第一页</asp:LinkButton>
  &nbsp;
  <asp:LinkButton ID="LinkButtonPrev" runat="server" 
  onclientclick="LinkButtonPrev_Click" onclick="LinkButtonPrev_Click">上一页</asp:LinkButton>
  &nbsp;
  <asp:LinkButton ID="LinkButtonNext" runat="server" 
  onclientclick="LinkButtonNext_Click" onclick="LinkButtonNext_Click">下一页</asp:LinkButton>
  &nbsp;
  <asp:LinkButton ID="LinkButtonLast" runat="server" 
  onclientclick="LinkButtonLast_Click" onclick="LinkButtonLast_Click">最后一页</asp:LinkButton> </div>

后台代码:
public partial class test10 : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
  if (!IsPostBack)
  {
  listbind();
  }
  }
  void listbind()
  { PagedDataSource pages = new PagedDataSource();
  string sqlconnstr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
  SqlDataAdapter sqld = new SqlDataAdapter("select * from products", sqlconnstr);
  DataSet ds = new DataSet();
  sqld.Fill(ds, "sql");
  using (SqlConnection sqlconn = new SqlConnection(sqlconnstr))
  {
  pages.DataSource = ds.Tables[0].DefaultView;
  pages.AllowPaging = true;
  pages.PageSize = 6;
  int Curpage = Convert.ToInt32(this.Label1.Text);
  pages.CurrentPageIndex = Curpage - 1;
  if (pages.CurrentPageIndex < 0)
  {
  pages.CurrentPageIndex = 0;
  }//只有一页时禁用上下页 
  if (pages.PageCount == 1)
  {
  LinkButtonPrev.Enabled = false;
  LinkButtonNext.Enabled = false;
  }
  else //多页时
  {
  //为第一页时
  if (Curpage == 1)
  {
  LinkButtonPrev.Enabled = false;
  LinkButtonNext.Enabled = true;
  }
  //为最后一页时
  if (Curpage == pages.PageCount)
  {
  LinkButtonPrev.Enabled = true;
  LinkButtonNext.Enabled = false;
  }
  }
  this.Label2.Text = Convert.ToString(pages.PageCount);
   
  DataList1.DataBind();

   
  }
 }
  //首页

 protected void LinkButtonFirst_Click(object sender, EventArgs e)
  {