如何在没有程序要求用户重新加载文件的情况下进行分页?这是代码。请引导我朝着正确的方向前进,或向我展示代码示例。
protected void btnUpload_Click(object sender, EventArgs e)
{
if (FileUpload1.PostedFile.FileName == string.Empty)
{
return;
}
else
{
string[] FileExt = FileUpload1.FileName.Split('.');
string FileEx = FileExt[FileExt.Length - 1];
if (FileEx.ToLower() == "csv")
{
FileUpload1.SaveAs(Server.MapPath(" " + FileUpload1.FileName));
}
else
{
return;
}
}
CSVReader reader = new CSVReader(FileUpload1.PostedFile.InputStream);
string[] headers = reader.GetCSVLine();
DataTable dt = new DataTable();
foreach (string strHeader in headers)
dt.Columns.Add(strHeader);
string[] data;
while ((data = reader.GetCSVLine()) != null)
dt.Rows.Add(data);
foreach (DataRow row in dt.Rows)
{
string dateAndTime = row["Date and Time"].ToString();
string personName = row["Description #2"].ToString();
string doorType = row["Card number"].ToString();
DateTime dateEntered = Convert.ToDateTime(dateAndTime);
DoorType doorTypeEnum;
bool personExists = false;
foreach (object name in EmployeeListBox.Items)
{
if (name.ToString() == personName)
{
personExists = true;
break;
}
}
if (!personExists)
{
EmployeeListBox.Items.Add(personName);
}
switch (doorType)
{
case "A02 - Rear Entrance":
doorTypeEnum = DoorType.RearEntranceDoor;
break;
case "B12 - Exterior Main Floor Man Trap":
doorTypeEnum = DoorType.ExteriorMainFloorDoor;
break;
case "B12 - Interior Main Floor Man Trap":
doorTypeEnum = DoorType.InteriorMainFloorDoor;
break;
case "C13 - Rear Break Room Door":
doorTypeEnum = DoorType.RearBreakRoomDoor;
break;
case "B02 - Exterior Basement Man Trap":
doorTypeEnum = DoorType.ExteriorBasementDoor;
break;
case "B02 - Interior Basement Man Trap":
doorTypeEnum = DoorType.InteriorBasementDoor;
break;
case "D01 - Managed Services Main door":
doorTypeEnum = DoorType.ManagedServicesDoor;
break;
case "D01 - Managed Services Big Door":
doorTypeEnum = DoorType.ManagedServicesBigDoor;
break;
default:
doorTypeEnum = DoorType.None;
break;
}
peopleEntering.Add(new PersonEntered(personName, dateEntered, doorTypeEnum));
}
for (int i = 0; i < peopleEntering.Count; i++)
{
DateTime startDate = new DateTime();
DateTime endDate = new DateTime();
string personName = peopleEntering[i].PersonName;
if (peopleEntering[i].DoorEntered == DoorType.RearEntranceDoor)
{
startDate = peopleEntering[i].DateOfEntry;
for (int j = i + 1; j < peopleEntering.Count; j++)
{
if (peopleEntering[j].DoorEntered == DoorType.ExteriorBasementDoor && peopleEntering[j].PersonName == personName)
{
endDate = peopleEntering[j].DateOfEntry;
}
}
}
workSpans.Add(new WorkSpan(personName, startDate, endDate));
}
if (IsPostBack )
{
this.csvReaderGv.DataSource = new DataTable();
this.csvReaderGv.DataSource = dt;
this.csvReaderGv.DataBind();
}
}
protected void csvReaderGv_SelectedIndexChanged(object sender, EventArgs e)
{
if (IsPostBack)
{
EmployeeListBox.Visible = true;
messagePanelBox.Visible = true;
DateAndTime.Text = csvReaderGv.SelectedRow.Cells[2].Text;
Description1.Text = csvReaderGv.SelectedRow.Cells[3].Text;
Description2.Text = csvReaderGv.SelectedRow.Cells[4].Text;
Cardnumber.Text = csvReaderGv.SelectedRow.Cells[5].Text;
List<WorkSpan> listOfWorkSpans = new List<WorkSpan>();
string personName = csvReaderGv.Rows[0].Cells[0].ToString();
for (int j = 0; j < workSpans.Count; j++)
{
if (workSpans[j].PersonName == personName)
{
listOfWorkSpans.Add(workSpans[j]);
}
}
}
}
protected void EmployeeListBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (IsPostBack)
{
string personName = EmployeeListBox.Items[EmployeeListBox.SelectedIndex].ToString();
List<WorkSpan> listOfWorkSpan = new List<WorkSpan>();
foreach (WorkSpan workSpan in workSpans)
{
if (workSpan.PersonName == personName)
{
listOfWorkSpan.Add(workSpan);
}
}
int b;
b = Convert.ToInt32(csvReaderGv.Rows[0].ToString());
csvReaderGv.DataSource = listOfWorkSpan;
DateAndTime.Text = csvReaderGv.Rows[b].Cells[2].ToString();
Description1.Text = csvReaderGv.Rows[b].Cells[3].ToString();
Description2.Text = csvReaderGv.Rows[b].Cells[4].ToString();
DateTime startDate = System.Convert.ToDateTime(csvReaderGv.Rows[b].Cells[2].ToString());
DateTime endDate = System.Convert.ToDateTime(csvReaderGv.Rows[b].Cells[2].ToString());
TimeSpan difference = endDate - startDate;
if (true)
{
keyedInHoursLbl.Text = difference.ToString();
keyedInHoursLbl.Visible = true;
}
else
{
}
}
}
protected void csvReaderGv_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
DataTable dt = new DataTable();
csvReaderGv.DataSource = dt;
csvReaderGv.DataBind();
}
请需要帮助。一直盯着这个问题,好几天了