//利用PageDataSource來做分頁功能 PagedDataSource pds = new PagedDataSource(); //將PageDataSource綁定SqlDataSource pds.DataSource = SqlDataSource1.Select(DataSourceSelectArguments.Empty); pds.AllowPaging = true; // 分頁大小 pds.PageSize = 6; int PageIndex; //分頁參數 if (!string.IsNullOrEmpty(Request.QueryString["Page"]) && int.TryParse(Request.QueryString["Page"], out PageIndex)) { PageIndex = Convert.ToInt32(Request.QueryString["Page"]); } else { PageIndex = 1; } pds.CurrentPageIndex = PageIndex - 1; // 最後一頁 if (!pds.IsLastPage) { hlNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(PageIndex + 1); if (Request.QueryString["type"] != null) hlNext.NavigateUrl += "&type=" + Request.QueryString["type"]; } else { hlNext.Visible = false; } //將DataList綁定PageDataSource this.DataList1.DataSource = pds; this.DataList1.DataBind();