⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 index.aspx.vb

📁 电子商务买书的网站
💻 VB
字号:



Public Class index
    Inherits System.Web.UI.Page

#Region " Web 窗体设计器生成的代码 "

    '该调用是 Web 窗体设计器所必需的。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents txtKeyword As System.Web.UI.WebControls.TextBox
    Protected WithEvents dropKeyField As System.Web.UI.WebControls.DropDownList
    Protected WithEvents btnSearch As System.Web.UI.WebControls.Button
    Protected WithEvents myCustomRepeater As nsASPNETCase.CustomRepeater
    Protected WithEvents myDataList As System.Web.UI.WebControls.DataList

    '注意: 以下占位符声明是 Web 窗体设计器所必需的。
    '不要删除或移动它。
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
        '不要使用代码编辑器修改它。
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在此处放置初始化页的用户代码
        If Not Page.IsPostBack Then
            Call myDataBind()
        End If
    End Sub
    '该过程用来绑定数据
    Sub myDataBind()

        '首先获取几个重要的变量,用以判断显示哪一个类别,显示第几页,查找关键词
        Dim intKindId, intCurrentPageIndex As Integer
        Dim strKeyword, strKeyField As String

        '下面获取当前显示什么类别
        If Request.QueryString("KindId") <> "" And (Not Page.IsPostBack) Then
            '这种情况表示刚刚打开了首页或者某一个栏目
            intKindId = Request.QueryString("KindId")  '获取传递过来的KindId
            Session("KindId") = intKindId     '保存到Session中
        Else
            '其它情况下从Session中获取
            intKindId = Session("KindId")
        End If

        '下面获取当前显示第几页
        If Request.QueryString("KindId") <> "" And (Not Page.IsPostBack) Then
            '这种情况表示刚刚打开了首页或者某一个栏目
            intCurrentPageIndex = 0
            Session("CurrentPageIndex") = intCurrentPageIndex
        Else
            '其它情况下从Session中获取
            intCurrentPageIndex = Session("CurrentPageIndex")
        End If

        '下面来获取查找关键词
        If Request.QueryString("KindId") <> "" And (Not Page.IsPostBack) Then
            '该情况表示刚打开首页或者某一个栏目,所以应该令关键词为默认的全部
            strKeyword = ""
            Session("Keyword") = strKeyword
            strKeyField = "BookName"
            Session("KeyField") = strKeyField
        Else
            '其它情况
            strKeyword = Session("Keyword")
            txtKeyword.Text = strKeyword   '设置查找关键词文本框的值
            strKeyField = Session("KeyField")
            dropKeyField.SelectedValue = strKeyField '设置查找字段的选中项
        End If

        '下面首先绑定myReapter控件,用来显示类别信息
        Dim dbs As New DataBusiness
        myDataList.DataSource = dbs.GetKind()
        myDataList.DataBind()


        '下面绑定myCustomRepeater控件,用来显示具体的书籍
        myCustomRepeater.CurrentPageIndex = intCurrentPageIndex
        myCustomRepeater.DataSource = dbs.GetBook(intKindId, strKeyword, strKeyField)
        myCustomRepeater.DataBind()
    End Sub

    Private Sub myCustomRepeater_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles myCustomRepeater.PageIndexChanged
        Session("CurrentPageIndex") = e.NewPageIndex    '将要显示的页码保存到Session中
        Call myDataBind()         '重新绑定数据
    End Sub

    '该过程用来查找记录
    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        '首先将查找关键词保存起来
        Session("Keyword") = txtKeyword.Text
        Session("KeyField") = dropKeyField.SelectedItem.Value
        '其次要设置当前显示页面
        Session("CurrentPageIndex") = 0

        '重新帮定数据
        Call myDataBind()
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -