2011-10-17 69 views
3

我希望我能解釋清楚:動態生成從2列超級鏈接在GridView的

我有一個GridView只顯示來自EntityDataSource的ID和名稱字段。

我想添加第三列,其中將包含與每個ID對應的動態生成的超鏈接。

但是,這些超鏈接的瀏覽只能通過連接對應於該ID的兩個其他字段(未顯示)來獲取。

假設我的數據源有如下數據:

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

我想看看下面的GridView,與超鏈接結構爲:

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

我該怎麼辦建設2列的超級鏈接?


我正在做一個ASP.NET Web窗體應用程序,實體類從數據庫逆向工程。但是,我爲分部類添加了只讀屬性。但我無法訪問它。以下是我的實體類中添加的內容

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

是否需要在別處添加任何代碼才能訪問此只讀屬性?

+0

謝謝你的編輯。正在爲此而掙扎。 –

+0

驗證MyEntity的2個部分位於相同的命名空間中。 –

回答

4

使用somethimg這樣在後面的代碼:

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

,並在GridView的列,使用您的aspx頁面:

<asp:TemplateField><ItemTemplate> 
    <asp:HyperLink ID="h1" runat="server" NavigateUrl='<% GetLink(Eval("Path"), Eval("FileName")) %>'>Download!</asp:HyperLink> 
</ItemTemplate></asp:TemplateField>