01.
Imports
System.Data
02.
Imports
System.Data.OleDb
03.
Partial
Class
DataList1
04.
Inherits
System.Web.UI.Page
05.
06.
Dim
objConn
As
OleDbConnection
07.
Dim
objCmd
As
OleDbCommand
08.
09.
Protected
Sub
Page_Load(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
Me
.Load
10.
Dim
strConnString
As
String
11.
strConnString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
& _
12.
Server.MapPath(
"database/mydatabase.mdb"
) &
";"
13.
objConn =
New
OleDbConnection(strConnString)
14.
objConn.Open()
15.
16.
BindData()
17.
End
Sub
18.
19.
Protected
Sub
BindData()
20.
Dim
strSQL
As
String
21.
strSQL =
"SELECT * FROM category"
22.
23.
Dim
dtReader
As
OleDbDataReader
24.
objCmd =
New
OleDbCommand(strSQL, objConn)
25.
dtReader = objCmd.ExecuteReader()
26.
27.
28.
myDataList.DataSource = dtReader
29.
myDataList.DataBind()
30.
31.
dtReader.Close()
32.
dtReader =
Nothing
33.
34.
End
Sub
35.
36.
Protected
Sub
Page_Unload(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Handles
Me
.Unload
37.
objConn.Close()
38.
objConn =
Nothing
39.
End
Sub
40.
41.
Protected
Sub
myDataList_ItemDataBound(
ByVal
sender
As
Object
,
ByVal
e
As
DataListItemEventArgs)
Handles
myDataList.ItemDataBound
42.
43.
Dim
img
As
Image =
CType
(e.Item.FindControl(
"imgPicture"
), Image)
44.
If
Not
IsNothing(img)
Then
45.
img.ImageUrl = e.Item.DataItem(
"Picture"
)
46.
47.
48.
End
If
49.
50.
51.
Dim
hplCate
As
HyperLink =
CType
(e.Item.FindControl(
"hplCategory"
), HyperLink)
52.
If
Not
IsNothing(hplCate)
Then
53.
hplCate.Text = e.Item.DataItem(
"CategoryName"
)
54.
hplCate.ToolTip = e.Item.DataItem(
"CategoryName"
)
56.
End
If
57.
End
Sub
58.
End
Class