/// <summary> /// 按前台分页样式为datatable增加空行 /// </summary> /// <param name="gridPageSize">grid分页行数</param> /// <param name="dt"></param> /// <returns></returns> public static DataTable FitDatatableRows(int gridPageSize, DataTable dt) { int needAddCount = 0; //需要添加的行数 int remainder = dt.Rows.Count % gridPageSize;//取余数 //当dt为空 或不是分页行数的整数倍时 if (dt.Rows.Count > 0 && remainder != 0 || dt.Rows.Count == 0) { needAddCount = gridPageSize - remainder; } for (int i = 0; i < needAddCount; i++) { dt.Rows.Add(new object[] { }); dt.AcceptChanges(); } return dt; }