Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Professional ASP.NET 3.5 in C# and Visual Basic Part 120. Building on the revolutionary ASP.NET 2.0 release, ASP.NET 3.5 adds several key new developer features including AJAX, LINQ, and a new CSS designer in Visual Web Developer 2008. The dramatic reduction in code that developers realized from the more than 50 new server controls in ASP.NET 2.0 now allows developers the time to make their applications more interactive with AJAX, to work with data in their preferred language with LINQ, and to build visually attractive and consistent standards-based sites with CSS. . | Chapter 25 File I O and Streams file. If you want to display only the filenames you could use the Directory class s GetFiles method which returns a simple string array of filenames. Figure 25-4 Listing 25-6 shows how to use the TreeView control s SelectedNodeChanged event to bind your Gridview with the file information. Listing 25-6 Binding a GridView to directory files VB script runat server Protected Sub Page_Load ByVal sender As Object ByVal e As System.EventArgs If Not Page.IsPostBack Then For Each drive As System.IO.DriveInfo In System.IO.DriveInfo.GetDrives Dim node As TreeNode New TreeNode node.Value drive.Name If drive.IsReady Then node.Text drive.Name - free space drive.AvailableFreeSpace LoadDirectories node drive.Name Else node.Text drive.Name - not ready End If Me.TreeViewl.Nodes.Add node Next End If Me.TreeViewl.CollapseAll Continued 1150 Chapter 25 File I O and Streams End Sub Private Sub LoadDirectories ByVal parent As TreeNode ByVal path As String Dim directory As System.IO.DirectoryInfo _ New System.IO.Directorylnfo path Try For Each d As System.IO.DirectoryInfo In directory.GetDirectories Dim node As TreeNode New TreeNode d.Name d.FullName parent.ChildNodes.Add node Recurse the current directory LoadDirectories node d.FullName Next Catch ex As System.UnauthorizedAccessException parent.Text Access Denied Catch ex As Exception parent.Text Unknown Error ex.Message End Try End Sub Protected Sub TreeView1_SelectedNodeChanged _ ByVal sender As Object ByVal e As System.EventArgs Dim directory As System.IO.DirectoryInfo _ New System.IO.DirectoryInfo Me.TreeView1.SelectedNode.Value Me.GridViewl.DataSource directory.GetFiles Me.GridView1.DataBind End Sub script html xmlns http www.w3.org 1999 xhtml head runat server title Binding a Gridview title head body form id form1 runat server div table tr td style width 100px valign top asp TreeView ID TreeView1 runat server OnSelectedNodeChanged TreeView1_SelectedNodeChanged asp TreeView td td valign top asp .