Click here to Skip to main content
16,020,673 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I'm using an aspx page that is inherited from master page. Have a GridView in the content page.
But GridView paging is not working. When I clicked on next page, nothing happened.
But it's working in normal ASPX page.

Here is my full code.
ASP
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder_Body" runat="server">
<asp:GridView ID="grdPdfShow" runat="server" AllowSorting="True" AutoGenerateColumns="False"
                        OnPageIndexChanging="grdPdfShow_PageIndexChanging" 
                        AllowPaging="True" PageSize="2">
                        <Columns>
                            <asp:BoundField DataField="FileId" HeaderText="Serial No" />
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <asp:Label ID="lblFileType" runat="server" Text='<%# Eval("FileType") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="File Content">
                                <ItemTemplate>
                                    <asp:TextBox ID="txtFileContent" runat="server" ReadOnly="True" 
                                        TextMode="MultiLine" Text='<%# Eval("FileContent") %>' Height="60px" 
                                        Width="200px"></asp:TextBox>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="File Name">
                                <ItemTemplate>
                                    <asp:LinkButton ID="lnkBtnFileName" runat="server" 
                                        Text='<%# Eval("FileName") %>' ToolTip="View File" 
                                        onclick="lnkBtnFileName_Click"></asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="">
                                <ItemTemplate>
                                    <asp:LinkButton ID="lnkBtnDownload" runat="server" 
                                        onclick="lnkBtnDownload_Click">Download</asp:LinkButton>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <PagerSettings FirstPageText="First" LastPageText="Last" 
                            Mode="NextPreviousFirstLast" NextPageText="Next" PreviousPageText="Previous" />
                    </asp:GridView>
</asp:Content>
And Code behind :
C#
protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                grdPdfShow.DataSource = GetDataForPdfGridView();
                grdPdfShow.DataBind();
            }
        }

        private DataTable GetDataForPdfGridView()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("FileId", typeof(int));
            dt.Columns.Add("FileType", typeof(string));
            dt.Columns.Add("FileContent", typeof(string));
            dt.Columns.Add("FileName", typeof(string));
            dt.Columns.Add("FilePath", typeof(string)); // not shown in Grid.
            int i = 1;
            foreach (var path in Directory.GetFiles(Server.MapPath("~/Resources/Articles/"), "*.pdf", SearchOption.TopDirectoryOnly))
            {
                dt.Rows.Add(i, "pdf", "Hello World", Path.GetFileName(path).ToString(), "~/Resources/Articles/" + Path.GetFileName(path));
                i++;
            }
            return dt;
        }

        protected void grdPdfShow_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            grdPdfShow.PageIndex = e.NewPageIndex;
            grdPdfShow.DataSource = GetDataForPdfGridView();
            grdPdfShow.DataBind();
            //grdPdfShow.PageIndex = e.NewPageIndex;
        }
Please help me ASAP. Thanks in Advance.
Posted
Updated 3-Aug-13 5:25am
v4
Comments
sumit_kapadia 4-Aug-13 3:56am    
Put and break point on grdPdfShow_PageIndexChanging and see whether event is reaching to server.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900