Reputation: 17
Previously I could download files from gridview and code in GridView1_RowCommand
code is
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "cmd")
{
string filename = e.CommandArgument.ToString();
string path = MapPath("~/Docfiles/" + filename);
byte[] bts = System.IO.File.ReadAllBytes(path);
Response.Clear();
Response.ClearHeaders();
Response.AddHeader("Content-Type", "Application/octet-stream");
Response.AddHeader("Content-Length", bts.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment; filename=" +
filename);
Response.BinaryWrite(bts);
Response.Flush();
but now I create a table and show some data and I want a download link in table here is table code...
<div class="CSSTableGenerator" >
<table border="0" width="100%" cellpadding="0" cellspacing="0"
id="results">
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<tr>
<td>
Document ID
</td>
<td >
Document Name
</td>
<td>
File Uploaded
</td>
<td>
Document Type
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<%--<td><asp:LinkButton ID="LinkButton1" runat="server"
CommandArgument='<%# Eval("FileUploaded") %>'
CommandName="cmd">Download</asp:LinkButton></td>--%>
<td><%#DataBinder.Eval(Container.DataItem,"DocumentID") %></td>
<td><%#DataBinder.Eval(Container.DataItem, "
DocumentName")%> </td>
<td><%#DataBinder.Eval(Container.DataItem,
"FileUploaded")%></td>
<td><%#DataBinder.Eval(Container.DataItem,
"Document")%></td>
</tr>
</ItemTemplate>
</asp:Repeater>
<div id="pageNavPosition" >
</div>
</table>
</div>
now how do I add a download link in table and what I write instead of GridView1_RowCommand ????
any solution?
Upvotes: 0
Views: 2989
Reputation: 92
I understand, you store files in some folder called "Docfiles". All you need to do add hyperlink in ItemTemplate on this file
<td><a href="/Docfiles/<%#DataBinder.Eval(Container.DataItem, "DocumentName")%>">Download</a></td>
GridView1_RowCommand not needed in this scenario
Upvotes: 1