正在阅读:Eric的超高效数据分页(图示+代码)Eric的超高效数据分页(图示+代码)

2004-09-13 14:41 出处:CSDN 作者:ericfine 责任编辑:linjixiong


  int records = 10000;
  int pages = 10;
  int pageSize = 15;
  SqlConnection conn = new SqlConnection("Server=(local);Database=megadata;User Id=sa;Password=xxx");

  void Page_Load(object sender, EventArgs e)
  {
  if (!IsPostBack)
  {
  dgBind(getSqlString(1));
  }

  int firstPage = int.Parse(hidFirstPage.Value);
  pnlButtons.Controls.Add(getPager(firstPage));
  lblPrompt.Text = "数据提取范围: <B>SELECT TOP " + records.ToString() + " megaid FROM megatable ORDER BY megaguid</B>";
  }

  string getSqlString(int selectedPage)
  {
  string[] idsStrArray;
  string sqlStr;

  if (Session["idStr"] != null)
  {
  idsStrArray = Session["idStr"].ToString().Split('#');
  }
  else
  {
  sqlStr = "SELECT TOP " + records.ToString() + " megaid FROM megatable ORDER BY megaguid";
  SqlCommand cmd = new SqlCommand(sqlStr, conn);
  conn.Open();
  SqlDataReader dr = cmd.ExecuteReader();
  StringBuilder sb = new StringBuilder("");
  int n = 1;

  while (dr.Read())
  {
  if (n % pageSize == 0)
  {
  sb.Append(dr[0].ToString() + "#");
  }
  else
  {
  sb.Append(dr[0].ToString() + ",");
  }

 


察看评论详细内容 我要发表评论
作者笔名 简短内容 发表时间
:

键盘也能翻页,试试“← →”键

相关文章

关注我们

最新资讯离线随时看 聊天吐槽赢奖品