Solved

Put Link in dynamic .Net Gridview

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

18 Experts available now in Live!

Get 1:1 Help Now