I want to display file list in the GridView like the following way inside the master page.
I wrote the same code but it is not showing me any file.
How to fix it? Here is my Code
<%@ Page Title="Handouts" Language="C#" MasterPageFile="~/Demo.master" AutoEventWireup="true"
CodeFile="frmHandouts.aspx.cs" Inherits="frmHandouts" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<div class="content-wrapper">
<div class="content">
<div class="connectedSortable" style="margin-left: 10px;">
<div class="col-sm-1">
</div>
<div class="col-md-10">
<div class="col-md-4 ">
<br />
<br />
<asp:Label ID="lblMessage" runat="server" Text="" Font-Names="Arial"></asp:Label>
</div>
<br /><br />
<div class="modal-content">
<div class="modal-header" style="background-color: #4682B4; color: #fff">
<h4><span class="fa fa-download"></span> Download Files</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-12 ">
<div class="table-responsive">
<asp:GridView runat="server" ID="grvDocuments" Width="100%" Class="table table-striped table-bordered table-hover"
AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="S.No">
<ItemTemplate>
<asp:Label ID="lblRowNumber" Text='<%# Container.DataItemIndex + 1 %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Text" HeaderText="Document Name" />
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:HyperLink ID="lnkView" Text="View" NavigateUrl='<%# Eval("Value", "~/frmHandoutsView.aspx?fileName={0}") %>'
runat="server" Target="_blank" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</asp:Content>
and code is
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["id"] != null)
{
int ITCode = int.Parse(Request.QueryString["id"].ToString());
GetDocuments(ITCode);
}
}
}
protected void GetDocuments(int ITCode)
{
string[] filePaths = Directory.GetFiles((@"C:\Reports" + ITCode));
List<ListItem> files = new List<ListItem>();
foreach (string filePath in filePaths)
{
files.Add(new ListItem(Path.GetFileName(filePath), filePath));
}
grvDocuments.DataSource = files;
grvDocuments.DataBind();
}