Solved

Put Link in dynamic .Net Gridview

Posted on 2010-09-03
3
292 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 125 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Latency in .net app using DB in .net 21 31
How can I use SQL Stored Procedure to return FedEx Zone 17 41
Run time Error 4 34
Capture logon name 13 42
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now