【问题标题】:asp.net DataGrid file structure and linking back to itasp.net DataGrid 文件结构并链接回它
【发布时间】:2012-04-16 16:17:10
【问题描述】:

我正在使用 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>

这是我的代码隐藏页面:

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

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

这个目录里面的文件是:

01.jpg
02.jpg
MyDoc.doc

我正在尝试为客户提供一个直接链接,让他们点击并下载它。似乎我能得到的唯一链接是文件夹examfilemanager中的名称“01.jpg”。

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

链接的href是01.jpg,我需要examfilemanager/01.jpg我怎样才能做到这一点?

【问题讨论】:

    标签: asp.net


    【解决方案1】:

    试试这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-03
      • 1970-01-01
      • 2013-12-15
      • 2011-12-10
      • 1970-01-01
      • 1970-01-01
      • 2011-08-16
      • 1970-01-01
      相关资源
      最近更新 更多