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

📄 message.aspx.vb

📁 是可以运行的电子光盘 有程序与PPT介绍 对于学习VB。NET的有参考意义
💻 VB
字号:
Imports System.Data
Imports System.data.OleDb
Imports System.Configuration.ConfigurationManager
Partial Class WebDisk_Message_Message
    Inherits System.Web.UI.Page
    '最大页数
    Protected MaxPage As Integer
    '最大行数
    Protected RowSum As Integer
    '当前页数
    Protected CurPage As Integer
    '每页显示数量
    Protected PageSz As Integer
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        '页面第一次加载
        If Not Page.IsPostBack Then
            '声明sql连接
            Dim strconn, strsql As String
            Dim myconn As oledbconnection
            Dim MyDataAdapter As OledbDataAdapter
            Dim DS As dataset
            '设置数据库连接
            strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(AppSettings("databasepath"))
            myconn = New oledbconnection(strconn)
            strsql = "SELECT * FROM Message ORDER BY ID DESC"
            MyDataAdapter = New OledbDataAdapter(strsql, myconn)
            DS = New DataSet()
            Try
                MyDataAdapter.Fill(DS)
                '获取总共有多少行
                RowSum = DS.Tables(0).Rows.Count
            Catch
                RowSum = 0
            End Try
            Dim PageDS As PagedDataSource = New PagedDataSource
            PageDS.DataSource = DS.Tables(0).DefaultView
            PageDS.AllowPaging = True
            '设置每页显示条数,可以修改。
            PageDS.PageSize = 5
            PageSz = PageDS.PageSize
            '没有指定页数时默认为第一页
            If Request.QueryString("Page") <> "" Then
                CurPage = Convert.ToInt32(Request.QueryString("Page"))
            Else
                CurPage = 1
            End If
            '计算出浏览数据的总页数
            If rowSum Mod PageSz > 0 Then
                '有余数要加1
                MaxPage = RowSum \ PageSz + 1
            Else
                '正好除尽
                MaxPage = RowSum \ PageSz
            End If
            '设置翻页
            PageDS.CurrentPageIndex = CurPage - 1
            lblCurrentPage.Text = "共有留言 " & RowSum & " 条,分 " & MaxPage & " 页," & "当前为第 " & CurPage & " 页," & "每页 " & PageSz & " 条"
            If Not PageDS.IsFirstPage Then
                lnkfirst.NavigateUrl = Request.CurrentExecutionFilePath & "?Page=1"
                lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath & "?Page=" & (CurPage - 1)
            End If
            If Not PageDS.IsLastPage Then
                lnkNext.NavigateUrl = Request.CurrentExecutionFilePath & "?Page=" & (CurPage + 1)
                lnklast.NavigateUrl = Request.CurrentExecutionFilePath & "?Page=" & MaxPage
            End If
            '数字链接
            Dim i As Integer
            For i = CurPage - 5 To CurPage + 5
                If CurPage = i Then
                    lblNumber.Text &= "<font color=#FF0000><strong>" & CurPage & "</strong></font>&nbsp;"
                ElseIf i <= MaxPage And i >= 1 Then

                    lblNumber.Text &= "<a href='" & Request.CurrentExecutionFilePath & "?Page=" & i & "'>" & i & "</a>&nbsp;"
                End If
            Next
            '绑定数据
            RepMain.DataSource = PageDS
            RepMain.DataBind()
        End If
    End Sub


    '管理员回复
    Function AdminRel(ByVal relmessage)
        If Not relmessage Is dbnull.value Then
            AdminRel = "<br><table width=100% border=0 cellpadding=2 cellspacing=0 bgcolor=#7896DC><tr><td><B>管理员回复:</B><br>&nbsp;&nbsp;" & relmessage & "</td></tr></table>"
        Else
            Return Nothing
        End If
    End Function

    '非管理员看不到回复和删除按钮
    Function ShowAdmin()
        If Convert.ToInt16(Session("LoginType")) = Data.LoginType.SUPUERMANAGER Then
            Return True
        Else
            Return False
        End If
    End Function

    Protected Sub RepMain_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles RepMain.ItemCommand
        If e.CommandName = "delete" Then
            'Dim index As Integer = e.Item.ItemIndex()
            'Dim img As ImageButton = CType(RepMain.Items(index).FindControl("Delete"), ImageButton)
            Dim ID As String = e.CommandArgument  'RepMain.Items(index).DataItem("id")

            Dim strconn, strsql As String
            Dim myconn As OleDbConnection
            Dim cmd As OleDbCommand
            '连接数据库
            strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(AppSettings("databasepath"))
            myconn = New OleDbConnection(strconn)
            strsql = "DELETE FROM Message WHERE ID=" & ID
            cmd = New OleDbCommand(strsql, myconn)
            Try
                myconn.Open()
                cmd.ExecuteNonQuery()
                myconn.Close()
            Catch ex As Exception
                myconn.Close()
                ' MsgBox("删除异常" & ex.Message)
                'Response.Redirect("error.aspx?error=delete")
            End Try

        End If
        Response.Redirect("Message.aspx")

    End Sub
End Class

⌨️ 快捷键说明

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