C#DataGridView分页显示数据
2021-01-07 05:28
标签:翻页 sele 查询 复制 ast current mamicode -- 技术 #region DataGridView分页 DataTable MiddleData = new DataTable(); //查询RawData中符合条件的数据 /// /// /// /// private void PageSorter(DataTable dataTable) // 总记录数 beginRecord = pageSize * (currentPage - 1); endRecord = pageSize * currentPage; if (currentPage == pageCount) endRecord = recordCount; for (int i = beginRecord; i { FlipOverData = dtTemp; //首页 //上一页 LoadPage(MiddleData); } LoadPage(MiddleData); } LoadPage(MiddleData); } #endregion C#DataGridView分页显示数据 标签:翻页 sele 查询 复制 ast current mamicode -- 技术 原文地址:https://www.cnblogs.com/z55w/p/13157811.html
private void QueryBtn_Click(object sender, EventArgs e)
{
MiddleData = commData.Select(RawData, $"NewTime > ‘{dateTime1}‘ and NewTime
PageSorter(MiddleData);
dataGridView1.DataSource = FlipOverData;
}
/// 每页记录数
///
public int pageSize = 22;
/// 总记录数
///
public int recordCount = 0;
/// 总页数
///
public int pageCount = 0;
/// 当前页
///
public int currentPage = 0;
{
recordCount = dataTable.Rows.Count;
// 总页数
pageCount = recordCount / pageSize;
if (recordCount % pageSize > 0)
{
pageCount++;
}
currentPage = 1;
LoadPage(dataTable);
}
private void LoadPage(DataTable dataTable)
{
//当前页小于1时,当前页=1
if (currentPage //当前页大于总页数时,当前页=总页数
if (currentPage > pageCount) currentPage = pageCount;
int beginRecord; //开始指针
int endRecord; //结束指针
DataTable dtTemp;
//克隆 DataTable 的结构,包括所有 DataTable 架构和约束。
dtTemp = dataTable.Clone();
if (currentPage == 1) beginRecord = 0;
// dataTable.Rows[i] 复制到 dtTemp 中,保留任何属性设置以及初始值和当前值。
dtTemp.ImportRow(dataTable.Rows[i]);
}
labPageIndex.Text = "当前页: " + currentPage.ToString() + " / " + pageCount.ToString();//当前页
labRecordCount.Text = "总行数: " + recordCount.ToString() + " 行";//总记录数
}
///
/// 记录翻页用到的数据
///
public DataTable FlipOverData { get; set; }
private void FirstPagBtn_Click(object sender, EventArgs e)
{
if (currentPage == 1)
{ return; }
currentPage = 1;
LoadPage(MiddleData);
dataGridView1.DataSource = FlipOverData;
}
private void UpPagBtn_Click(object sender, EventArgs e)
{
if (currentPage == 1)
{ return; }
currentPage--;
dataGridView1.DataSource = FlipOverData;
//下一页
private void NextPagBtn_Click(object sender, EventArgs e)
{
if (currentPage == pageCount)
{ return; }
currentPage++;
dataGridView1.DataSource = FlipOverData;
//尾页
private void LastPagBtn_Click(object sender, EventArgs e)
{
if (currentPage == pageCount)
{ return; }
currentPage = pageCount;
dataGridView1.DataSource = FlipOverData;
文章标题:C#DataGridView分页显示数据
文章链接:http://soscw.com/index.php/essay/40638.html