?
Solved

Put Link in dynamic .Net Gridview

Posted on 2010-09-03
3
Medium Priority
?
299 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

771 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