允许分页动态gridview

时间:2017-10-02 06:02:25

标签: c# asp.net gridview

我有一个动态创建步骤的向导控件。每个步骤都包含一个动态创建的gridview控件。

该页面允许用户上传多个excel文件,然后在向导控件中显示这些文件。更具体地说,文件显示在网格视图中,网格视图是在向导控件的步骤中动态创建的。

如何以编程方式启用每个gridview的分页?标记如下所示:

fibbo3 = Memoize(fibbo3)

背后的代码如下所示:

    <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="true" CodeFile="FileUpload_Multi.aspx.cs" Inherits="Analysis_Files_FileUpload_Multi" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
   <span style="font-family: Arial">Supported file formats: .csv, .xls, .xlsx<br />
    <br />
    Click to add files</span>
   <asp:Button ID="btnAdd" Text="Add" OnClick="OnAdd" runat="server" />
   <asp:Panel ID="pnlTemp" runat="server">
   </asp:Panel>
   <br />
   <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" />
    <asp:Label ID="lbl_upload" runat="server" Text="No file added!" 
        Visible="False"></asp:Label>
    <asp:Label ID="lbl_fileformat" runat="server" Text="File format not supported!" Visible="False"></asp:Label>
    <br />
    <br />
    <asp:Panel id="wizardPanel" runat="server" >
    </asp:Panel>
    <br />
</asp:Content>

1 个答案:

答案 0 :(得分:1)

您可以像这样语法设置Paging。

GridView1.DataSource = ds.Tables[0];

GridView1.AllowPaging = true;
GridView1.PageSize = 50;
GridView1.PageIndexChanged += GridView1_PageIndexChanged;

GridView1.DataBind();

您必须记住,因为您将这些绑定到动态创建的控件,并且更改页面导致PostBack,必须在每个PostBack上重新创建GrdView控件。