用ASP、NET开发下载系统(三)

类别:.NET开发 点击:0 评论:0 推荐:

ASPNET开发下载系统()

 

前台界面部分

主界面

主界面是左上部分是一个TreeView控件,用来添加分类信息。

主界面是左下部分是一个List控件,用来显示下载信息排行榜。

主界面是右边部分是一个DataGrid控件,用来显示下载信息。

这是一个基本的界面,如果需要更多功能,请自行扩充!

       步骤:新建一项目(选择asp.net应用程序),添加Web 引用, 重命名为DownWS

在窗体上添加DataGrid,用属性生成器设置其属性:列、分页、格式等,然后在代码中为DataGrid设置数据源,再绑定后,呈现上述样式。

 

 

 

再添加TreeViewList等控件。在程序中将数据添加到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 窗体设计器所必需的。

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

 

    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 & "\tree.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("<script language='javascript'>open('" + strUrl + "','pop','directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,height=450,width=595');</script>")

 

    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

 

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"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML>

       <HEAD>

              <title>XX下载系统</title>

              <meta content="Microsoft Visual Studio .NET 7.0" name="GENERATOR">

              <meta content="Visual Basic 7.0" name="CODE_LANGUAGE">

              <meta content="JavaScript" name="vs_defaultClientScript">

              <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">

       </HEAD>

       <body MS_POSITIONING="GridLayout">

              <form id="Form1" method="post" runat="server">

                     <FONT face="宋体">

                            <DIV style="Z-INDEX: 101; LEFT: 150px; WIDTH: 741px; POSITION: absolute; TOP: 82px; HEIGHT: 412px" ms_positioning="FlowLayout"><FONT face="宋体"><asp:datagrid id="DataGrid1" runat="server" ForeColor="Black" BackColor="White" AllowPaging="True" AutoGenerateColumns="False" Height="212px" Width="739px" BorderColor="#6876C5" GridLines="Vertical" PageSize="20">

                                                 <SelectedItemStyle ForeColor="White" BackColor="DeepSkyBlue"></SelectedItemStyle>

                                                 <AlternatingItemStyle BackColor="#EEEEEE"></AlternatingItemStyle>

                                                 <HeaderStyle ForeColor="White" BackColor="#6876C5"></HeaderStyle>

                                                 <FooterStyle ForeColor="White" BackColor="#6876C5"></FooterStyle>

                                                 <Columns>

                                                        <asp:BoundColumn DataField="id" HeaderText="编号">

                                                               <HeaderStyle Width="80px"></HeaderStyle>

                                                        </asp:BoundColumn>

                                                        <asp:BoundColumn DataField="classname" HeaderText="分类名称">

                                                               <HeaderStyle Width="120px"></HeaderStyle>

                                                        </asp:BoundColumn>

                                                        <asp:HyperLinkColumn DataNavigateUrlFormatString="webform2.aspx?ID={0}" DataTextField="title" HeaderText="标题" NavigateUrl="filename">

                                                               <HeaderStyle Width="320px"></HeaderStyle>

                                                        </asp:HyperLinkColumn>

                                                        <asp:BoundColumn DataField="uploadtime" HeaderText="上传时间">

                                                               <HeaderStyle Width="180px"></HeaderStyle>

                                                        </asp:BoundColumn>

                                                        <asp:BoundColumn DataField="totaldown" HeaderText="下载次数">

                                                               <HeaderStyle Width="100px"></HeaderStyle>

                                                        </asp:BoundColumn>

                                                        <asp:ButtonColumn Text="下载" HeaderText="下载" CommandName="Select">

                                                               <HeaderStyle Width="60px"></HeaderStyle>

                                                        </asp:ButtonColumn>

                                                 </Columns>

                                                 <PagerStyle HorizontalAlign="Center" ForeColor="White" BackColor="#6876C5" Mode="NumericPages"></PagerStyle>

                                          </asp:datagrid></FONT></DIV>

                            <DIV style="Z-INDEX: 103; LEFT: 19px; WIDTH: 131px; POSITION: absolute; TOP: 81px; HEIGHT: 497px" ms_positioning="FlowLayout"><asp:label id="Label2" runat="server" ForeColor="White" BackColor="#6876C5" Width="129px">软件分类 </asp:label><iewc:treeview id="TreeView1" runat="server"></iewc:treeview><asp:label id="Label3" runat="server" ForeColor="White" BackColor="#6876C5" Width="129px">下载排行</asp:label><asp:listbox id="ListBox1" runat="server" Height="191px" Width="130px"></asp:listbox></DIV>

              </form>

              </FONT>

       </body>

</HTML>

 

 

 

--------------------------------------------------------------------------

Author : lihonggen0

个人专栏:http://www.csdn.net/develop/author/netauthor/lihonggen0/

如需引用,请指明出处!软件的目的在于应用,本文可自由转载!

--------------------------------------------------------------------------

 

本文地址:http://com.8s8s.com/it/it45534.htm