幸运星空

Lucker的程序人生

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  • DataList控件实现分页功能

SqlConnection con = new SqlConnection(Convert.ToString(ConfigurationManager.ConnectionStrings["ConnectionString"]));

string conString = "SELECT [CompanyName], [CustomerID] FROM [Reports_Customers] ORDER BY [CustomerID]";

con.Open();

SqlDataAdapter da = new SqlDataAdapter(conString, con);

DataSet ds = new DataSet();

da.Fill(ds);

PagedDataSource pds = new PagedDataSource();

pds.AllowPaging = true;

pds.PageSize = 10;

pds.DataSource = ds.Tables[0].DefaultView;

Int32 totPage, curPage;

totPage = 0;

curPage = 0;

lnkprev.Visible = true;

lnkfirst.Visible = true;

lnknext.Visible = true;

lnklast.Visible = true;

totPage = pds.PageCount;

if (Request.QueryString["Page"] != null)

{

    curPage = Convert.ToInt32( Request.QueryString["Page"]);

}

else

{

    curPage = 1;

}

pds.CurrentPageIndex = curPage - 1;

lbpage.Text = "当前第" + Convert.ToString(curPage) + "页,共" + Convert.ToString(totPage) + "页";

lnkfirst.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=1";

lnklast.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + totPage.ToString();

if (!pds.IsFirstPage)

{

    lnkprev.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(curPage - 1);

}

else

{

    lnkprev.Visible = false;

    lnkfirst.Visible = false;

}

if (!pds.IsLastPage)

{

    lnknext.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(curPage + 1);

}

else

{

    lnknext.Visible = false;

    lnklast.Visible = false;

}

CustomerList.DataSource = pds;

CustomerList.DataBind();

posted on 2008-12-04 23:38  Lucker  阅读(229)  评论(0编辑  收藏  举报