001.
<%@ Page Language=
"VB"
%>
002.
<%@ import
Namespace
=
"System.Data"
%>
003.
<%@ import
Namespace
=
"System.Data.OleDb"
%>
004.
<script runat=
"server"
>
005.
Dim
strKeyWord
As
String
006.
Sub
Page_Load(sender
As
Object
, e
As
EventArgs)
007.
strKeyWord =
Me
.txtKeyWord.Text
008.
End
Sub
009.
010.
Sub
BindData()
011.
012.
Dim
objConn
As
New
OleDbConnection
013.
Dim
objCmd
As
New
OleDbCommand
014.
Dim
dtAdapter
As
New
OleDbDataAdapter
015.
Dim
ds
As
New
DataSet
016.
Dim
strConnString,strSQL
As
String
017.
018.
strConnString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
&Server.MapPath(
"database/mydatabase.mdb"
)&
";Jet OLEDB:Database Password=;"
019.
strSQL =
"SELECT * FROM customer WHERE (Name like '%"
& strKeyWord &
"%' OR Email like '%"
& strKeyWord &
"%') "
020.
021.
objConn.ConnectionString = strConnString
022.
With
objCmd
023.
.Connection = objConn
024.
.CommandText = strSQL
025.
.CommandType = CommandType.Text
026.
End
With
027.
dtAdapter.SelectCommand = objCmd
028.
029.
dtAdapter.Fill(ds)
030.
031.
032.
myGridView.DataSource = ds
033.
myGridView.DataBind()
034.
035.
dtAdapter =
Nothing
036.
objConn.Close()
037.
objConn =
Nothing
038.
039.
End
Sub
040.
041.
Sub
myGridView_RowDataBound(sender
As
Object
, e
As
GridViewRowEventArgs)
042.
043.
Dim
lblCustomerID
As
Label =
CType
(e.Row.FindControl(
"lblCustomerID"
),Label)
044.
IF
Not
IsNothing(lblCustomerID)
Then
045.
lblCustomerID.Text = e.Row.DataItem(
"CustomerID"
)
046.
End
IF
047.
048.
049.
Dim
lblName
As
Label =
CType
(e.Row.FindControl(
"lblName"
),Label)
050.
IF
Not
IsNothing(lblName)
Then
051.
lblName.Text = e.Row.DataItem(
"Name"
)
052.
End
IF
053.
054.
055.
Dim
lblEmail
As
Label =
CType
(e.Row.FindControl(
"lblEmail"
),Label)
056.
IF
Not
IsNothing(lblEmail)
Then
057.
lblEmail.Text = e.Row.DataItem(
"Email"
)
058.
End
IF
059.
060.
061.
Dim
lblCountryCode
As
Label =
CType
(e.Row.FindControl(
"lblCountryCode"
),Label)
062.
IF
Not
IsNothing(lblCountryCode)
Then
063.
lblCountryCode.Text = e.Row.DataItem(
"CountryCode"
)
064.
End
IF
065.
066.
067.
Dim
lblBudget
As
Label =
CType
(e.Row.FindControl(
"lblBudget"
),Label)
068.
IF
Not
IsNothing(lblBudget)
Then
069.
lblBudget.Text = FormatNumber(e.Row.DataItem(
"Budget"
),2)
070.
End
IF
071.
072.
073.
Dim
lblUsed
As
Label =
CType
(e.Row.FindControl(
"lblUsed"
),Label)
074.
IF
Not
IsNothing(lblUsed)
Then
075.
lblUsed.Text = FormatNumber(e.Row.DataItem(
"Used"
),2)
076.
End
IF
077.
End
Sub
078.
079.
Sub
btnSearch_Click(sender
As
Object
, e
As
EventArgs)
080.
BindData()
081.
End
Sub
082.
083.
</script>
084.
<html>
085.
<head>
086.
<title>ThaiCreate.Com ASP.NET - Microsoft Access</title>
087.
</head>
088.
<body>
089.
<form id=
"form1"
runat=
"server"
>
090.
<asp:Label id=
"lblKeyword"
runat=
"server"
text=
"Keyword"
></asp:Label>
091.
<asp:TextBox id=
"txtKeyWord"
runat=
"server"
></asp:TextBox>
092.
<asp:Button id=
"btnSearch"
onclick=
"btnSearch_Click"
runat=
"server"
Text=
"Search"
></asp:Button>
093.
<br />
094.
<br />
095.
<asp:GridView id=
"myGridView"
runat=
"server"
096.
AutoGenerateColumns=
"False"
onRowDataBound=
"myGridView_RowDataBound"
>
097.
<HeaderStyle backcolor=
"#cccccc"
></HeaderStyle>
098.
<AlternatingRowStyle backcolor=
"#e8e8e8"
></AlternatingRowStyle>
099.
<Columns>
100.
<asp:TemplateField HeaderText=
"CustomerID"
>
101.
<ItemTemplate>
102.
<asp:Label id=
"lblCustomerID"
runat=
"server"
></asp:Label>
103.
</ItemTemplate>
104.
</asp:TemplateField>
105.
<asp:TemplateField HeaderText=
"Name"
>
106.
<ItemTemplate>
107.
<asp:Label id=
"lblName"
runat=
"server"
></asp:Label>
108.
</ItemTemplate>
109.
</asp:TemplateField>
110.
<asp:TemplateField HeaderText=
"Email"
>
111.
<ItemTemplate>
112.
<asp:Label id=
"lblEmail"
runat=
"server"
></asp:Label>
113.
</ItemTemplate>
114.
</asp:TemplateField>
115.
<asp:TemplateField HeaderText=
"CountryCode"
>
116.
<ItemTemplate>
117.
<asp:Label id=
"lblCountryCode"
runat=
"server"
></asp:Label>
118.
</ItemTemplate>
119.
</asp:TemplateField>
120.
<asp:TemplateField HeaderText=
"Budget"
>
121.
<ItemTemplate>
122.
<asp:Label id=
"lblBudget"
runat=
"server"
></asp:Label>
123.
</ItemTemplate>
124.
</asp:TemplateField>
125.
<asp:TemplateField HeaderText=
"Used"
>
126.
<ItemTemplate>
127.
<asp:Label id=
"lblUsed"
runat=
"server"
></asp:Label>
128.
</ItemTemplate>
129.
</asp:TemplateField>
130.
</Columns>
131.
</asp:GridView>
132.
</form>
133.
</body>
134.
</html>