以前我可以从gridview和GridView1_RowCommand
中的代码下载文件代码是
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();
但是现在 我创建一个表并显示一些数据,我想在表中下载一个链接 这是表格代码......
<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>
现在如何在表格中添加下载链接以及我写的内容而不是GridView1_RowCommand ????
任何解决方案?
答案 0 :(得分:1)
据我所知,您将文件存储在名为“Docfiles”的文件夹中。 您只需要在此文件的ItemTemplate中添加超链接
<td><a href="/Docfiles/<%#DataBinder.Eval(Container.DataItem, "DocumentName")%>">Download</a></td>
此场景中不需要GridView1_RowCommand