用 ASP 、 NET 开发下载系统 ( 三 )
前台界面部分
主界面
主界面是左上部分是一个 TreeView 控件,用来添加分类信息。
主界面是左下部分是一个 List 控件,用来显示下载信息排行榜。
主界面是右边部分是一个 DataGrid 控件,用来显示下载信息。
这是一个基本的界面,如果需要更多功能,请自行扩充!
步骤:新建一项目 ( 选择 asp.net 应用程序 ) ,添加 Web 引用 , 重命名为 DownWS
在窗体上添加 DataGrid ,用属性生成器设置其属性:列、分页、格式等,然后在代码中为 DataGrid 设置数据源,再绑定后,呈现上述样式。
再添加 TreeView , List 等控件。在程序中将数据添加到 TreeView ,详细代码请见下面:
注:
Internet Explorer WebControls 不在 VS.NET 的标准 Server Control 中,到微软的站点下载: http://msdn.microsoft.com/downloads/samples/internet/default.asp?url=/Downloads/samples/Internet/ASP_DOT_NET_ServerControls/WebControls/default.asp 下载安装后第一次使用时,要右击工具箱 Customize Toolbox …→ .NET Framework Components 中找到 Micosoft.Web.UI.WebControls.Treeview 后选中,这样 Treeview 控件就出现在工具箱中了。
downinfo.aspx.vb:
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.Web.UI.WebControls
Public Class downInfo
Inherits System.Web.UI.Page
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents TreeView1 As Microsoft.Web.UI.WebControls.TreeView
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Protected WithEvents ListBox1 As System.Web.UI.WebControls.ListBox
Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm
Region " Web 窗体设计器生成的代码 "
' 该调用是 Web 窗体设计器所必需的。
1<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
2
3End Sub
4
5Private Sub Page_Init( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase .Init
6
7' CODEGEN: 此方法调用是 Web 窗体设计器所必需的
8
9' 不要使用代码编辑器修改它。
10
11InitializeComponent()
12
13End Sub
14
15# End Region
16
17Dim downDv As New DataView()
18
19Dim strName As String
20
21Private Sub Page_Load( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase .Load
22
23'
24
25strName = Request.QueryString("strName")
26
27' 实例化一个 DownWebService
28
29Dim WS As New DownWS.DownWebService()
30
31Dim dsTree As DataSet
32
33' 得到所有的分类
34
35dsTree = WS.GetDownClass
36
37' 填充到树状结构中
38
39TreeView1.Nodes.Clear()
40
41Dim Row As DataRow
42
43For Each Row In dsTree.Tables(0).Rows
44
45Dim item As New TreeNode()
46
47item.Text = Row.Item("classname").ToString
48
49' 点击时的网址跳转
50
51item.NavigateUrl = "downinfo.aspx?strname=" & Row.Item("classname").ToString
52
53' 每个分支的图片
54
55item.ImageUrl = ResolveUrl( Me .TemplateSourceDirectory & "\tree.jpg")
56
57TreeView1.Nodes.Add(item)
58
59Next
60
61' 得到所有下载信息 , 进行分类的过滤后,填充到 DataGrid
62
63downDv = WS.GetDownInfo().Tables(0).DefaultView
64
65If strName <> "" Then
66
67downDv.RowFilter = "classname='" & strName & "'"
68
69End If
70
71DataGrid1.DataSource = downDv
72
73DataGrid1.DataBind()
74
75End Sub
76
77Private Sub DataGrid1_SelectedIndexChanged( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.SelectedIndexChanged
78
79' 得到当前的 ID
80
81Dim nID As Int32 = DataGrid1.SelectedItem.Cells(0).Text
82
83' 得到 URL
84
85Dim strUrl As String = "downdetail.aspx?ID=" + nID.ToString()
86
87' 打开一个窗口 , 没有工具栏,状态条
88
89Response.Write("<script language="javascript">open('" + strUrl + "','pop','directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,height=450,width=595');</script>")
90
91End Sub
92
93Private Sub DataGrid1_PageIndexChanged( ByVal source As Object , ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
94
95' 处理分页
96
97DataGrid1.CurrentPageIndex = e.NewPageIndex
98
99DataGrid1.DataSource = downDv
100
101DataGrid1.DataBind()
102
103End Sub
104
105End Class
106
107### downinfo.aspx:
@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls, Version=1.0.2.226, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
@ Page Language="vb" AutoEventWireup="false" Codebehind="downInfo.aspx.vb" Inherits="WebApplication9.downInfo"
1
2<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
3
4<html>
5<head>
6<title>XX 下载系统 </title>
7<meta content="Microsoft Visual Studio .NET 7.0" name="GENERATOR"/>
8<meta content="Visual Basic 7.0" name="CODE_LANGUAGE"/>
9<meta content="JavaScript" name="vs_defaultClientScript"/>
10<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"/>
11</head>
12<body ms_positioning="GridLayout">
13<form id="Form1" method="post" runat="server">
14<font face=" 宋体 ">
15<div ms_positioning="FlowLayout" style="Z-INDEX: 101; LEFT: 150px; WIDTH: 741px; POSITION: absolute; TOP: 82px; HEIGHT: 412px"><font face=" 宋体 "><asp:datagrid allowpaging="True" autogeneratecolumns="False" backcolor="White" bordercolor="#6876C5" forecolor="Black" gridlines="Vertical" height="212px" id="DataGrid1" pagesize="20" runat="server" width="739px">
16<selecteditemstyle backcolor="DeepSkyBlue" forecolor="White"></selecteditemstyle>
17<alternatingitemstyle backcolor="#EEEEEE"></alternatingitemstyle>
18<headerstyle backcolor="#6876C5" forecolor="White"></headerstyle>
19<footerstyle backcolor="#6876C5" forecolor="White"></footerstyle>
20<columns>
21<asp:boundcolumn datafield="id" headertext=" 编号 ">
22<headerstyle width="80px"></headerstyle>
23</asp:boundcolumn>
24<asp:boundcolumn datafield="classname" headertext=" 分类名称 ">
25<headerstyle width="120px"></headerstyle>
26</asp:boundcolumn>
27<asp:hyperlinkcolumn datanavigateurlformatstring="webform2.aspx?ID={0}" datatextfield="title" headertext=" 标题 " navigateurl="filename">
28<headerstyle width="320px"></headerstyle>
29</asp:hyperlinkcolumn>
30<asp:boundcolumn datafield="uploadtime" headertext=" 上传时间 ">
31<headerstyle width="180px"></headerstyle>
32</asp:boundcolumn>
33<asp:boundcolumn datafield="totaldown" headertext=" 下载次数 ">
34<headerstyle width="100px"></headerstyle>
35</asp:boundcolumn>
36<asp:buttoncolumn commandname="Select" headertext=" 下载 " text=" 下载 ">
37<headerstyle width="60px"></headerstyle>
38</asp:buttoncolumn>
39
40</Columns</columns></asp:datagrid></font></div></font></form></body></html></system.diagnostics.debuggerstepthrough()>