3

I hope I can explain this clearly:

I have a GridView that only displays an ID and Name field from an EntityDataSource.

I want to add a third column that will contain a dynamically generated hyperlink corresponding to each ID.

However,the navigateurl for these hyperlinks can only be obtained by concatenating two other fields (that are not displayed) corresponding to the ID.

Suppose my DataSource had the following data:

[ID] [Name] [Path] [FileName]
 1    ABC    path1  file1
 2    XYZ    path2  file2

I want to see the following gridview, with the hyperlink constructed as:

|ID | NAME | Hyperlink      |             
----------------------------|                
 1  | ABC  | path1/file1.pdf|
 2  | XYZ  | path2/file2.pdf|

How do I do construct a hyperlink from 2 columns?


I'm doing an ASP.NET web form application, with the entity classes reverse engineered from the database. However, I added a read only property to a partial class. But I'm unable to access it. Here's what I added to my Entities class

public partial class MyEntity 
{ 
   public string FilePath 
   { 
      get { return string.Format("{0}/"{1}.pdf", this.FileName, this.FilePath); } 
   } 
} 

Do I need to add any code elsewhere to access this read-only property?

H H
  • 263,252
  • 30
  • 330
  • 514
colonel_px
  • 305
  • 4
  • 16

1 Answers1

3

use somethimg like this in code behind:

protected string GetLink(object oPath, object oFileName) {
    return string.Format("~/{0}/{1}.pdf", oPath.ToString(), oFileName.ToString());
}

and in your aspx page in gridview's column, use:

<asp:TemplateField><ItemTemplate>
    <asp:HyperLink ID="h1" runat="server" NavigateUrl='<% GetLink(Eval("Path"), Eval("FileName")) %>'>Download!</asp:HyperLink>
</ItemTemplate></asp:TemplateField>
ahmad molaie
  • 1,512
  • 2
  • 21
  • 41