简体   繁体   中英

ASP.NET C# Datagrid hyperlinks

What I'm trying to do here is have a datagrid show a list of files on the server which the user can click on to download, or open. The list populates with the files just fine, I get a whole list of all the pdf files in the folder. When I go to click on them in the datagrid, the link is directed to the application root directory and not to the proper folders. How do I tell a datagrid hyperlink column where to go?

C# code behind:

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>  

I tried placing this in:

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

but I get a "databinding expressions are only supported on objects that have a databinding event." error

Here you go.

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

Found it here. asp.net DataGrid file structure and linking back to it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM