<%@ Page Language="VB" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
Dim strKeyWord As String
Sub Page_Load(sender As Object, e As EventArgs)
strKeyWord = Me.txtKeyWord.Text
End Sub
Sub BindData()
Dim objConn As New OleDbConnection
Dim objCmd As New OleDbCommand
Dim dtAdapter As New OleDbDataAdapter
Dim ds As New DataSet
Dim strConnString, strSQL As String
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("database/data_system.mdb") & ";"
strSQL = "SELECT * FROM master WHERE (Computer_name like '%" & strKeyWord & "%' OR User_Name like '%" & strKeyWord & "%') "
objConn.ConnectionString = strConnString
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(ds)
'*** BindData to GridView ***'
myGridView.DataSource = ds
myGridView.DataBind()
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
End Sub
Sub myGridView_RowDataBound(sender As Object, e As GridViewRowEventArgs)
'*** ID_No ***'
Dim lblID_No As Label = CType(e.Row.FindControl("lblID_No"), Label)
If Not IsNothing(lblID_No) Then
lblID_No.Text = e.Row.DataItem("ID_No")
End If
'*** Computer_name ***'
Dim lblComputer_name As Label = CType(e.Row.FindControl("lblComputer_name"), Label)
If Not IsNothing(lblComputer_name) Then
lblComputer_name.Text = e.Row.DataItem("Computer_name")
End If
'*** User_Name ***'
Dim lblUser_Name As Label = CType(e.Row.FindControl("lblUser_Name"), Label)
If Not IsNothing(lblUser_Name) Then
lblUser_Name.Text = e.Row.DataItem("User_Name")
End If
'*** Department ***'
Dim lblDepartment As Label = CType(e.Row.FindControl("lblDepartment"), Label)
If Not IsNothing(lblDepartment) Then
lblDepartment.Text = e.Row.DataItem("Department")
End If
'*** Area ***'
Dim lblArea As Label = CType(e.Row.FindControl("lblArea"), Label)
If Not IsNothing(lblArea) Then
lblArea.Text = FormatNumber(e.Row.DataItem("Area"), 2)
End If
'*** Model ***'
Dim lblModel As Label = CType(e.Row.FindControl("lblModel"), Label)
If Not IsNothing(lblModel) Then
lblModel.Text = FormatNumber(e.Row.DataItem("Model"), 2)
End If
End Sub
Sub ShowPageCommand(s As Object, e As GridViewPageEventArgs)
myGridView.PageIndex = e.NewPageIndex
BindData()
End Sub
Sub btnSearch_Click(sender As Object, e As EventArgs)
BindData()
End Sub
</script>
<html>
<head>
<title>Search Data Collection System</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label id="lblKeyword" runat="server" text="Keyword"></asp:Label>
<asp:TextBox id="txtKeyWord" runat="server"></asp:TextBox>
<asp:Button id="btnSearch" onclick="btnSearch_Click" runat="server" Text="Search"></asp:Button>
<br />
<br />
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/data_collection/database/data_system.mdb"
SelectCommand="SELECT * FROM [master]"></asp:AccessDataSource>
<asp:GridView id="myGridView" runat="server"
AutoGenerateColumns="False" onRowDataBound="myGridView_RowDataBound"
OnPageIndexChanging="ShowPageCommand" PageSize="2" DataKeyNames="ID_No"
DataSourceID="AccessDataSource1">
<headerstyle BackColor="#cccccc"></headerstyle>
<AlternatingRowStyle backcolor="#e8e8e8"></AlternatingRowStyle>
<columns>
<asp:BoundField DataField="ID_No" HeaderText="ID_No" ReadOnly="True"
SortExpression="ID_No" />
<asp:BoundField DataField="Computer_name" HeaderText="Computer_name"
SortExpression="Computer_name" />
<asp:BoundField DataField="User_Name" HeaderText="User_Name"
SortExpression="User_Name" />
<asp:BoundField DataField="Department" HeaderText="Department"
SortExpression="Department" />
<asp:BoundField DataField="Area" HeaderText="Area" SortExpression="Area" />
<asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" />
<asp:BoundField DataField="Serial_No" HeaderText="Serial_No"
SortExpression="Serial_No" />
<asp:BoundField DataField="HDD" HeaderText="HDD" SortExpression="HDD" />
<asp:BoundField DataField="RAM" HeaderText="RAM" SortExpression="RAM" />
<asp:BoundField DataField="Mac_Address" HeaderText="Mac_Address"
SortExpression="Mac_Address" />
<asp:BoundField DataField="OS" HeaderText="OS" SortExpression="OS" />
<asp:BoundField DataField="Antivirus_Version" HeaderText="Antivirus_Version"
SortExpression="Antivirus_Version" />
<asp:BoundField DataField="SCCM" HeaderText="SCCM" SortExpression="SCCM" />
<asp:BoundField DataField="IE_Version" HeaderText="IE_Version"
SortExpression="IE_Version" />
<asp:BoundField DataField="Office_Version" HeaderText="Office_Version"
SortExpression="Office_Version" />
<asp:BoundField DataField="Asset_No" HeaderText="Asset_No"
SortExpression="Asset_No" />
<asp:BoundField DataField="Capital_Date" HeaderText="Capital_Date"
SortExpression="Capital_Date" />
<asp:BoundField DataField="Checker_By" HeaderText="Checker_By"
SortExpression="Checker_By" />
<asp:BoundField DataField="Check_Date" HeaderText="Check_Date"
SortExpression="Check_Date" />
<asp:BoundField DataField="Update_Date" HeaderText="Update_Date"
SortExpression="Update_Date" />
<asp:BoundField DataField="IP_Address" HeaderText="IP_Address"
SortExpression="IP_Address" />
<asp:BoundField DataField="Station_Code" HeaderText="Station_Code"
SortExpression="Station_Code" />
<asp:BoundField DataField="Have_UPS" HeaderText="Have_UPS"
SortExpression="Have_UPS" />
<asp:BoundField DataField="Other_Device" HeaderText="Other_Device"
SortExpression="Other_Device" />
</columns>
</asp:GridView>
</form>
</body>
</html>