I'm trying to populate a grid with a list of files that are in a folder. I'm able to do that fine, but can't figure out how to pass a hyper link into my gridview. It keeps coming out literally.
Code attached. Here's the line that I need to change:
row["Link"] = "<a href=metadata.aspx?file=" + fi.Name + ">Add Track Info</a>";
// Detect the user, then check their folder for new tracks DirectoryInfo di = new DirectoryInfo("C:\\FTP\\Catalog_DropFolder\\" + Profile.UserName); FileInfo[] rgFiles = di.GetFiles("*.wav"); foreach(FileInfo fi in rgFiles) { row = dtFiles.NewRow(); row["FileName"] = fi.Name; row["Link"] = "<a href=metadata.aspx?file=" + fi.Name + ">Add Track Info</a>"; dtFiles.Rows.Add(row); }
It depends on how that field is bound in our gridview. You might try defining that bound column as such:
<asp:TemplateField>
<ItemTemplate><%# Eval("Link") %></ItemTemplate>
</asp:TemplateField>
JT_SIRO
ASKER
That worked! Thanks.
Can you tell me why that works? Is it because the Eval function renders HTML?
<asp:TemplateField>
<ItemTemplate><%# Eval("Link") %></ItemTemplate>
</asp:TemplateField>