0
我想在兩個日期之間讀取文件並將值添加到數據表。然後想要在具有分頁的網格中顯示數據表值。但問題是,這些文件包含大量的數據(超過1M),所以如果我使用gridview默認分頁我的應用程序掛起。所以我想在datatable.so中分頁,我該怎麼做?任何想法的示例代碼請。如何在C#中使用數據表進行分頁#
public DataTable CreateDataSource(DateTime fromDate, DateTime toDate)
{
int i = 0;
string visitorCountry = "";
try
{
dt = dtVisitLog();
for (DateTime x = fromDate; x <= toDate; x = x.AddDays(1))
{
string startDate = x.Year.ToString().Substring(2, 2) + x.Month.ToString("d2") + x.Day.ToString("d2");
string FILE_NAME = pathName + "\\u_ex" + startDate + ".log";
if (File.Exists(FILE_NAME))
{
FileStream fs = new FileStream(FILE_NAME, FileMode.Open, FileAccess.Read,
FileShare.ReadWrite);
StreamReader sr = new StreamReader(fs);
string strResult = sr.ReadToEnd();
sr.Dispose();
fs.Dispose();
sr = null;
fs = null;
string[] arLogLines = strResult.Split(Convert.ToChar("\n"));
for (i = arLogLines.Length-2; i > 3; i--)
{
string[] attribute = arLogLines[i].Split(Convert.ToChar(" "));
dt.Rows.Add(attribute[0], attribute[1], attribute[8], attribute[4], attribute[7], visitorCountry);
}
}
}
return dt;
}
catch (Exception ex)
{
return null;
}
}