I have a grid view showing product images:
<form id="form1" runat="server">
<asp:Button ID="btnDownload" runat="server" CssClass="dist-down-button" Text="Download Selected" OnClick="DownloadFiles" />
<asp:Button ID="Button1" runat="server" CssClass="dist-down-button" Text="Download All" OnClick="DownloadAll" />
<asp:GridView ID="GridView1" runat="server" CssClass="mydatagrid" PagerStyle-CssClass="pager" HeaderStyle-CssClass="header" RowStyle-CssClass="rows" AllowPaging="True" OnPageIndexChanging="datagrid_PageIndexChanging" AutoGenerateColumns="false" EmptyDataText="No files available">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
<asp:Label ID="lblFilePath" runat="server" Text='<%# Eval("Value") %>' Visible="false"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Text" HeaderText="Image Name" />
</Columns>
</asp:GridView>
</form>
Binding function: (matches all the files in the products folder with the product images list from database and show matching products)
protected void BindData()
{
images = GetProductImages();
string[] filePaths = Directory.GetFiles(Server.MapPath("~/upload/Products/"));
List<ListItem> files = new List<ListItem>();
foreach (string filePath in filePaths)
{
if (images.IndexOf(Path.GetFileName(filePath)) > -1)
{
files.Add(new ListItem(Path.GetFileName(filePath), filePath));
}
}
GridView1.DataSource = files;
GridView1.DataBind();
}
protected void datagrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BindData();
}
Download All function: (look for the gridview list and download all the files listed)
protected void DownloadAll(object sender, EventArgs e)
{
using (ZipFile zip = new ZipFile())
{
zip.AlternateEncodingUsage = ZipOption.AsNecessary;
zip.AddDirectoryByName(ProductUrl);
foreach (GridViewRow row in GridView1.Rows)
{
string filePath = (row.FindControl("lblFilePath") as Label).Text;
zip.AddFile(filePath, ProductUrl);
}
Response.Clear();
Response.BufferOutput = false;
string zipName = String.Format("Zip_{0}.zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"));
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "attachment; filename=" + zipName);
zip.Save(Response.OutputStream);
Response.End();
}
}
When I click on Download All button it was downloading all the files correctly. BUT after I added the pagination the download all is now only downloading the current page.
Note: The checkbox is for selected download function. As you see I am not looking for checkboxes checked in the DownloadAll function.
Does anyone know why is this happening eventhough I am not looking for any checkbox in my function?