在将 GridView 的 Allowpage 设置为 true 后,我使用 GridView 来显示 excel 文件中的数据。所有页面都显示与第一页相同的内容。感谢任何告诉我原因的人!
GrdiView 的 HTML 代码是:
<asp:GridView ID="GridView_NewStaff" runat="server" AutoGenerateColumns="False"
CellPadding="4" Font-Size="Small" ForeColor="#333333" AllowPaging="True"
AllowSorting="True" onpageindexchanging="GridView_NewStaff_PageIndexChanging"
PageSize="20">
<pagersettings firstpagetext="First" lastpagetext="Last">
Mode="NextPreviousFirstLast" NextPageText="Next" PageButtonCount="4"
PreviousPageText="Previous" />
<columns>......
C#代码是:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindGridView();
}
}
protected void Button_ReadFile_Click(object sender, EventArgs e)
{
bindGridView();
}
public void bindGridView()
{
if (FileUpload_StaffInfo.HasFile)
{
string InfoFile_Name = Server.MapPath(InfoFileDirectory) + FileUpload_StaffInfo.FileName;
FileUpload_StaffInfo.SaveAs(InfoFile_Name);
dataTable_Excel = new DataTable();
if (InfoFile_Name.EndsWith(".xlsx"))//Read Excel2007-2010 format file
{
StaffExcelXML StaffNewXML = new StaffExcelXML();
StaffNewXML.ExcelInput(InfoFile_Name, ref dataTable_Excel)
}
else if (InfoFile_Name.EndsWith(".xls"))//Read Excel1997-2003 format file
{
StaffXLS StaffNewXLS = new StaffXLS();
StaffNewXLS.ExcelInput(InfoFile_Name, ref dataTable_Excel);
}
GridView_NewStaff.DataSource = dataTable_Excel;
GridView_NewStaff.DataBind();
}
}
protected void GridView_NewStaff_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView_NewStaff.PageIndex = e.NewPageIndex;
bindGridView();
}