Link to home
Start Free TrialLog in
Avatar of JT_SIRO
JT_SIRO

asked on

Put Link in dynamic .Net Gridview

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);
        }

Open in new window

Avatar of ChadFolden
ChadFolden

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>
Avatar of JT_SIRO

ASKER

That worked!  Thanks.

Can you tell me why that works?  Is it because the Eval function renders HTML?  
ASKER CERTIFIED SOLUTION
Avatar of ChadFolden
ChadFolden

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial