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

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


  pnlPager.Controls.Add(getLinkButton("Lst", "末页", "pgBtn", pageCount.ToString()));
  return pnlPager;
  }

  LinkButton getLinkButton(string lbId, string lbText, string lbCmdName, string lbCmdArg)
  {
  LinkButton lb = new LinkButton();
  lb.ID = lbCmdName + lbId;
  lb.Text = lbText;
  lb.CommandName = lbCmdName;
  lb.CommandArgument = lbCmdArg;
  lb.Command += new CommandEventHandler(pageTurn);
  return lb;
  }
  
  void pageTurn(object sender, CommandEventArgs e)
  {
  LinkButton lb = (LinkButton)sender;
  int selectedPage = int.Parse(lb.CommandArgument);
  int firstPage = selectedPage / pages * pages;
  firstPage = (selectedPage % pages == 0) ? (firstPage - pages) : firstPage;
  hidFirstPage.Value = firstPage.ToString();
  dgBind(getSqlString(selectedPage));
  pnlButtons.Controls.RemoveAt(pnlButtons.Controls.Count - 1);
  pnlButtons.Controls.Add(getPager(firstPage));
  lb = (LinkButton)pnlButtons.Controls[pnlButtons.Controls.Count - 1].FindControl("pgBtn" + selectedPage.ToString());
  lb.Enabled = false;
  }
  
  void dgBind(string sqlStr)
  {
  SqlDataAdapter da = new SqlDataAdapter(sqlStr, conn);
  DataTable dt = new DataTable();
  conn.Open();
  da.Fill(dt);
  conn.Close();
  da.Dispose();
  dg.DataSource = dt;
  dg.DataBind();
  }

  void dg_ItemDataBound(object sender, DataGridItemEventArgs e)
  {
  dg.Controls[0].EnableViewState = false;
  }

 


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

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

相关文章

关注我们

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