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

.NET ProgrammingASP.NET

Avatar of undefined
Last Comment
ChadFolden

8/22/2022 - Mon
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>
JT_SIRO

ASKER
That worked!  Thanks.

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

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23