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: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 :
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));
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();
}
Please help me ASAP. Thanks in Advance.