0

i have a gridview that i filled it with filenames from a path, know, i want the filenames to be clickable so i can download them and i don't know how, can someone help me. code-behind (file is the gridview ID)

string path = "//the path";
string[] Fname = Directory.GetFiles(path).Select(Path.GetFileName).ToArray();
file.DataSource = Fname;
file.DataBind(); 

the web page

<asp:GridView ID="file" runat="server" style="border:hidden" ></asp:GridView>
Jalloul95
  • 206
  • 1
  • 2
  • 10
  • Please look at this question: https://stackoverflow.com/questions/19798685/how-to-create-a-link-in-gridview-in-asp-net . I believe this is similar problem. – atomicicebreaker Aug 10 '17 at 10:30

2 Answers2

0

You can bind a single list/array item and get it in the ItemTemplate like this:

<asp:GridView ID="GridView1" runat="server">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <a target="_blank" href="<%# Container.DataItem %>">
                    <%# Container.DataItem %>
                </a>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
Martin Lindgren
  • 374
  • 2
  • 14
VDWWD
  • 35,079
  • 22
  • 62
  • 79
0
    <asp:HyperLink ID="UserId" runat="server" DataNavigateUrlFields="UserId" NavigateUrl='<%# "~/Report.aspx?name=" %>' 
                Text='<%# Eval("UserId") %>' ></asp:HyperLink>
            </ItemTemplate>
        </asp:TemplateField>
Karan
  • 47
  • 4