利用DataGrid显示某目录下的所有文件

1.*.ASPX
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm3.aspx.vb" Inherits="WebApplication1.WebForm3"%>
<HTML>
 <script language="VB" runat="server">
 
 </script>
 <body>
  <form runat="server">
   <div align="center">
    <asp:DataGrid runat="server" id="articleList" AutoGenerateColumns="False" BorderColor="#E7E7FF"
     BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="3" GridLines="Horizontal"
     Height="176px" Width="549px">
     <SelectedItemStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#738A9C"></SelectedItemStyle>
     <AlternatingItemStyle BackColor="#F7F7F7"></AlternatingItemStyle>
     <ItemStyle ForeColor="#4A3C8C" BackColor="#E7E7FF"></ItemStyle>
     <HeaderStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#4A3C8C"></HeaderStyle>
     <FooterStyle ForeColor="#4A3C8C" BackColor="#B5C7DE"></FooterStyle>
     <Columns>
      <asp:BoundColumn DataField="Name" HeaderText="文件名"></asp:BoundColumn>
      <asp:BoundColumn DataField="LastWriteTime" HeaderText="最后修改時間" DataFormatString="{0:d}">
       <ItemStyle HorizontalAlign="Center"></ItemStyle>
      </asp:BoundColumn>
      <asp:BoundColumn DataField="Length" HeaderText="文件大小" DataFormatString="{0:#,### 字節}">
       <ItemStyle HorizontalAlign="Right"></ItemStyle>
      </asp:BoundColumn>
     </Columns>
     <PagerStyle HorizontalAlign="Right" ForeColor="#4A3C8C" BackColor="#E7E7FF" Mode="NumericPages"></PagerStyle>
    </asp:DataGrid>
   </div>
  </form>
 </body>
</HTML>


2.*.aspx.vb

Imports System.IO

 

Public Class WebForm3

    Inherits System.Web.UI.Page

 

#Region " Web Form 設計工具產生的程式碼 "

 

    '此為 Web Form 設計工具所需的呼叫。

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

 

    End Sub

    Protected WithEvents articleList As System.Web.UI.WebControls.DataGrid

 

    '注意: 下列預留位置宣告是 Web Form 設計工具需要的項目。

    '請勿刪除或移動它。

    Private designerPlaceholderDeclaration As System.Object

 

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init

        'CODEGEN: 此為 Web Form 設計工具所需的方法呼叫

        '請勿使用程式碼編輯器進行修改。

        InitializeComponent()

    End Sub

 

#End Region

 

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        '在這裡放置使用者程式碼以初始化網頁

        Dim dirInfo As New DirectoryInfo(Server.MapPath("/WebApplication1/images"))

        articleList.DataSource = dirInfo.GetFiles("*.*")

        articleList.DataBind()

 

    End Sub

 

End Class

 

3.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值