首页 > 应用开发 > IT综合 > 用ASP、NET开发下载系统(三) (转)
主界面是左上部分是一个TreeView控件,用来添加分类信息。
主界面是左下部分是一个List控件,用来显示下载信息排行榜。
主界面是右边部分是一个DataGrid控件,用来显示下载信息。
这是一个基本的界面,如果需要更多功能,请自行扩充!
2003-7-21703370.jpg">
步骤:新建一项目(选择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控件就出现在工具箱中了。
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 窗体设计器所必需的。
End Sub
Private Sub Page_Init(ByVal sender As System.object, ByVal e As System.EventArgs) Handles MyBase.Init
' CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Dim downDv As New DataView()
Dim strName As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'
strName = Request.QueryString("strName")
'实例化一个Downwebservice
Dim WS As New DownWS.DownWebService()
Dim dsTree As DataSet
'得到所有的分类
dsTree = WS.GetDownClass
'填充到树状结构中
TreeView1.Nodes.Clear()
Dim Row As DataRow
For Each Row In dsTree.Tables(0).Rows
Dim item As New TreeNode()
item.Text = Row.Item("classname").ToString
'点击时的网址跳转
item.NavigateUrl = "downinfo.aspx?strname=" & Row.Item("classname").ToString
'每个分支的图片
item.ImageUrl = ResolveUrl(Me.TemplatesourceDirectory & " ree.jpg")
TreeView1.Nodes.Add(item)
Next
'得到所有下载信息,进行分类的过滤后,填充到DataGrid
downDv = WS.GetDownInfo().Tables(0).DefaultView
If strName <> "" Then
downDv.RowFilter = "classname='" & strName & "'"
End If
DataGrid1.DataSource = downDv
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_selectedIndExchanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.SelectedIndexChanged
'得到当前的ID
Dim nID As Int32 = DataGrid1.SelectedItem.Cells(0).Text
'得到URL
Dim strUrl As String = "downdetail.aspx?ID=" + nID.ToString()
'打开一个窗口,没有工具栏,状态条
Response.Write("")
End Sub
Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
'处理分页
DataGrid1.CurrentPageIndex = e.NewPageIndex
DataGrid1.DataSource = downDv
DataGrid1.DataBind()
End Sub
End Class
<%@ 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"%>
w3c//DTD HTML 4.0 Transitional//EN">
Visual Studio .net 7.0" name="GENERATOR">
Visual Basic 7.0" name="CODE_LANGUAGE">
Javascript" name="vs_defaultClientScript">
intellisense/IE5" name="vs_targetSchema">
--------------------------------------------------------------------------
Author : lihonggen0
个人专栏:http://www.csdn.net/develop/author/netauthor/lihonggen0/
如需引用,请指明出处!软件的目的在于应用,本文可自由转载!
--------------------------------------------------------------------------
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10748419/viewspace-958339/ ,如需转载,请注明出处,否则将追究法律责任。