Private Sub Page_(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
End Sub
Private Sub ibtnsubmit_Click(ByVal sender As Object,ByVal e As System.Web.UI. Image—ClickEventArgs)Handles ibtnsubmit.Click
Dim MyConnection As SqlConnection
Dim MyCommand As String
MyConnection=New SqlConnection(”server=(local);database=componentsystem;Trusted_Connection=yes”)
MyCommand=”select*from tb_userinformation where(UserID=’”+txtadminid.Text+”’
and Password=’”+txtadminpwd.Text+”’)”
Dim ds As DataSet=New DataSet()
Dim mycommand2 As SqlDataAdapter=New SqlDataAdapter(MyCommand,MyConnection)
mycommand2.Fill(ds)
myDataGrid.DataSource=New DataView(ds.Tables(0))
myDataGrid.DataBind()
If myDataGrid.Items.Count <;>;”0”Then
lblstatues.Style(”color”)=”red”
lblstatues.Text=”登录成功”
MyConnection.Close()
Session(”Admin”)=”true”
Response.Redirect(”leftadmin.aspx”)
Else
lblstatues.Style(”color”)=”red”
lblstatues.Text=”登录失败”
MyConnection.Close()
End If
End Sub
Private Sub ibtncancel_Click(ByVal sender As System.Object,ByVal e As System.Web.UI.
ImageClickEventArgs)Handles ibtncancel.Click
txtadminid.Text=””
txtadminpwd.Text=””
lblstatues.Text=””
End Sub
End Class
12.关于构件页面(管理员)
说明:以下代码为添加、删除、修改、浏览关于构件页面的VB代码。
页面1
Imports System.Data
Imports System.Data.SqlClient
Public Class aboutcomplist
Inherits System.Web.UI.Page
Protected WithEvents Image1 As System.Web.UI.WebControls.Image
Protected WithEvents MyDataGrid As System.Web.UI.WebControls.DataGrid
Protected WithEvents btnadmin As System.Web.UI.WebControls.Button
Region”Web窗体设计器生成的代码”
’该调用是Web窗体设计器所必需的。
Private Sub InitializeComponent()
End Sub
Private Sub Page_(ByVal sender As System.Object,ByVal e As System.EventArgs)
Handles MyBase.Init
’CODEGEN:此方法调用是Web窗体设计器所必需的
’不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Private startIndex As Integer
Private Sub Binding()
Dim MyConnection As SqlConnection
MyConnection=New SqlConnection(”server=(local);database=componentsystem;Trusted_Connection=yes”)
MyConnection.Open()
Dim mySQL As String=”SELECT ArticleID,Title,Writer,WriteTime,Counter FROM tb_componentintroduction ORDER BY WriteTime DESC”
Dim myDataSet As DataSet=New DataSet()
Dim myCommand As SqlDataAdapter=New SqlDataAdapter(mySQL,MyConnection)
myCommand.Fill(myDataSet,”introduce”)
MyConnection.Close()
MyDataGrid.DataSource=myDataSet.Tables(”introduce”).DefaultView
MyDataGrid.DataBind()
End Sub
Private Sub Page_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)
Handles MyBase.Load
If Not IsPostBack Then
startIndex=0
End If
Binding()
If Session(”admin”)=””Then
btnadmin.Visible=False
Else
btnadmin.Visible=True
End If
’在此处放置初始化页的用户代码
End Sub
Private Sub MyDataGrid_PageIndexChanged(ByVal source As Object,ByVal e AsSystem.Web.UI. WebControls.DataGridPageChangedEventArgs)Handles MyData—Grid.PageIndexChanged
startIndex=e.NewPageIndex*MyDataGrid.PageSize
MyDataGrid.CurrentPageIndex=e.NewPageIndex
Binding()
End Sub
Private Sub btnadmin_Click(ByVal sender As System.Object,ByVal e AsSystem.EventArgs)Handles btnadmin.Click
Response.Redirect(”aboutcompadmin.aspx”)
End Sub
End Class
页面2
Imports System.Data
Imports System.Data.SqlClient
Public Class aboutcompadmin
Inherits System.Web.UI.Page
Protected WithEvents Image1 As System.Web.UI.WebControls.Image
Protected WithEvents MyDataGrid As System.Web.UI.WebControls.DataGrid
Protected WithEvents btnadd As System.Web.UI.WebControls.Button
Protected WithEvents btndel As System.Web.UI.WebControls.Button