[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Put Link in dynamic .Net Gridview

Posted on 2010-09-03
3
Medium Priority
?
305 Views
Last Modified: 2013-12-17
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

0
Comment
Question by:JT_SIRO
  • 2
3 Comments
 
LVL 4

Expert Comment

by:ChadFolden
ID: 33598577
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>
0
 

Author Comment

by:JT_SIRO
ID: 33598741
That worked!  Thanks.

Can you tell me why that works?  Is it because the Eval function renders HTML?  
0
 
LVL 4

Accepted Solution

by:
ChadFolden earned 500 total points
ID: 33598814
Yes, that's basically the reason.  
When you bind a gridview column to a datatable who's column is of a string data type, the gridview is going to output that value as a string.  When you use the Eval (or Container.DataItem), you're basically telling it to put that string in the HTML, this rendering it as html.
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month19 days, 21 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question