主要代码如下
/// <summary> /// 读取指定页面的数据 /// </summary> /// <param name="pagePerCount">每页显示的行数</param> /// <param name="page">当前第几页</param> /// <returns>总行数</returns> private int ReadTableData(int pagePerCount, int page) { if (page < 1) return 0; int listRow = 0; this._dataTableTempValue.Clear(); _dataTableTempValue = _dataTableValue.Copy(); _dataTableTempValue.Rows.Clear(); foreach (DataRow row in _dataTableValue.Rows) { if ((listRow >= ((page - 1) * pagePerCount)) && (listRow < (page * pagePerCount))) { _dataTableTempValue.ImportRow(_dataTableValue.Rows[listRow]); } listRow++; } int totalPages = Convert.ToInt32(listRow / pagePerCount + ((listRow % pagePerCount) == 0 ? 0 : 1)); this.TotalPages = totalPages; if (page > this.TotalPages) page = this.TotalPages; this.UpdatePage(totalPages, totalPages > 0 ? page : 0); this.ControlEnable(); dataGrid.ItemsSource = DataTableTempValue.DefaultView; return listRow; }
运行界面
时间: 2024-10-13 20:54:22