使用数据表进行数据分页

我有一个存储大量记录的数据表。有一个名为ID的列,它是一个种子为1的自动增量。 我已经实现了分页控件。我知道我需要显示的第一个和最后一个记录的ID,但我不知道如何从数据表中提取特定的行,或者它是否确实可行。是否可能,或者我是否需要使用数据集? 我正在使用名为SiteFinity的CMS产品,因此我无法访问数据库以使用SQLDataAdapter或类似的,     
已邀请:
这可能不是一个非常优雅的解决方案,但它可能适合您。 我假设您将能够根据下面的代码找出您的起始索引和下一个索引。
DataTable dt = GetTable(); // this represents where your datatable is coming from
DataTable temp = dt.Clone();
DataRow[] rows = dt.Select("ID >= 1"); //insert the next begining index

int pageSize = 5;
int ctr = 0;
foreach(var row in rows)
{
    DataRow r = temp.NewRow();

    r["ID"] = row["ID"]; 
    r["Name"] = row["Name"];

   temp.Rows.Add(r); //its neccesary to create a new datarow or you'll get an exception if u add a row already belonging to a datatable

  ctr++;

  if(ctr == pageSize) break;
}

//at this point temp hold either 0 rows or <= pageSize rows and you can bind your control to it.
    

要回复问题请先登录注册