日期:2014-05-17  浏览次数:20381 次

repeater分页理解问题
protected void Page_Load(object sender, EventArgs e)
  {
  if (!IsPostBack) {
  SqlConnection conn = DB.getConnection();
  conn.Open();
  SqlCommand Count = new SqlCommand();
  Count.Connection = conn;
  Count.CommandText = "select count(*) from T_SoftDown1";
  AspNetPager1.RecordCount = (int)Count.ExecuteScalar();
  //Response.Write(AspNetPager1.RecordCount);
  conn.Close();
  BindData();
  }

  }

  public void BindData()
  {
  SqlConnection conn = DB.getConnection();
  string sql = "select * from T_SoftDown1 order by E_id desc";//这句在大型数据中应该用:select top查询语句
  SqlDataAdapter da = new SqlDataAdapter(sql, conn);
  DataSet ds = new DataSet();
  da.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "temptbl");
  DataTable dt = ds.Tables["temptbl"];
  SoftDown.DataSource=dt;
  SoftDown.DataBind();
  }

上面调用下面的方法,可是上下都有sql语句,各自代表什么意思呢?

------解决方案--------------------
"select count(*)只是得到总记录数
select * from T_SoftDown1 order by E_id desc
才是得到具体的内容
------解决方案--------------------
上面count(*)是统计记录总数 下面查询是查询所有数据赋值给数据源