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

王朝asp·作者佚名  2006-12-17
窄屏简体版  字體: |||超大  

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

利用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.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航