asp.net的DataGrid文件结构和链接回吧 [英] asp.net DataGrid file structure and linking back to it

查看:167
本文介绍了asp.net的DataGrid文件结构和链接回吧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用一个DataGrid:

I am using a DataGrid:

<asp:DataGrid runat="server" ID="articleList" UseAccessibleHeader="true" AutoGenerateColumns="false" AlternatingItemStyle-BackColor="#EEEEEE" HeaderText="File Name">
    <Columns>
        <asp:HyperLinkColumn DataNavigateUrlField="DirectoryName" DataTextField="Name" HeaderText="File Name" />
        <asp:BoundColumn DataField="LastWriteTime" HeaderText="Modified" ItemStyle-HorizontalAlign="Center" DataFormatString="{0:f}" />
        <asp:BoundColumn DataField="Length" HeaderText="Size" ItemStyle-HorizontalAlign="Right" DataFormatString="{0:#,### bytes}" />
        <asp:BoundColumn DataField="Extension" HeaderText="Type" ItemStyle-HorizontalAlign="Left" />
    </Columns>
</asp:DataGrid>

下面是我的code-隐藏页:

Here is my code-behind page:

protected void Page_Load(object sender, EventArgs e)
{
    DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath("examfilemanager"));

    articleList.DataSource = dirInfo.GetFiles();
    articleList.DataBind();
}

在这个目录里的文件是:

The files inside this directory are:

01.jpg
02.jpg
MyDoc.doc

我想提供一个直接链接,客户端点击下载此。这似乎是唯一的链接,我可以得到的是名为01.JPG,这是一个文件夹里面examfilemanager

I am trying to provide a direct link for the client to click on and download this. It seems the only links I can get are the name "01.jpg" which is inside a folder examfilemanager.

文件信息属性的名称属性返回只是名字。 (01.JPG)

The Name property of the file info properties returns just the name. (01.jpg)

链接的href是01.JPG,我需要的是 examfilemanager / 01.JPG 我怎样才能让这一切成为可能?

The href of the link is 01.jpg, I need that to be examfilemanager/01.jpg how can i make this possible?

推荐答案

试试这个:

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

这篇关于asp.net的DataGrid文件结构和链接回吧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆