【问题标题】:ASP.NET C# Datagrid hyperlinksASP.NET C# Datagrid 超链接
【发布时间】:2012-06-03 22:55:24
【问题描述】:

我在这里尝试做的是让数据网格显示服务器上的文件列表,用户可以单击以下载或打开这些文件。该列表很好地填充了文件,我得到了文件夹中所有 pdf 文件的完整列表。当我在数据网格中单击它们时,链接被定向到应用程序根目录而不是正确的文件夹。 如何告诉数据网格超链接列去哪里?

后面的C#代码:

DirectoryInfo dir = new DirectoryInfo(Server.MapPath("~") + "/Assets/reports/");
gridList.DataSource = dir.GetFiles("*.pdf");
gridList.DataBind();

asp

<asp:DataGrid runat="server" id="gridList" Font-Name="Verdana"
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="Name" DataTextField="Name" 
       HeaderText="File Name"/>
</Columns>
</asp:DataGrid>  

我试着把它放在:

 NavigateUrl =  '<%# "~/Assets/reports/" + Eval("Name") %>'>

但我得到一个“数据绑定表达式仅在具有数据绑定事件的对象上受支持。”错误

【问题讨论】:

  • 当您在第一个代码 sn-p 中绑定到文件时,实际呈现的 URL 是什么?此外,如果您想使用 Eval() 来构建该链接,那么我建议您只使用 TemplateColumn 并手动构建链接:msdn.microsoft.com/en-us/library/aa479316.aspx

标签: c# asp.net datagrid hyperlink


【解决方案1】:

给你。

<asp:HyperLinkColumn DataNavigateUrlField="Name" 
  DataTextField="Name" 
  HeaderText="File Name"
  DataNavigateUrlFormatString="~\examfilemanager\{0}" />

在这里找到。 asp.net DataGrid file structure and linking back to it

【讨论】:

  • 谢谢!我先在这里寻找解决方案,但显然我错过了。
猜你喜欢
  • 2011-08-16
  • 1970-01-01
  • 1970-01-01
  • 2015-08-10
  • 1970-01-01
  • 1970-01-01
  • 2011-10-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多