001.
<%@ Page Language=
"VB"
%>
002.
<%@ import
Namespace
=
"System.Data"
%>
003.
<%@ import
Namespace
=
"System.Data.OleDb"
%>
004.
<script runat=
"server"
>
005.
Dim
objConn
As
OleDbConnection
006.
Dim
objCmd
As
OleDbCommand
007.
008.
Sub
Page_Load(sender
As
Object
, e
As
EventArgs)
009.
Dim
strConnString
As
String
010.
strConnString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
& _
011.
Server.MapPath(
"database/mydatabase.mdb"
)&
";"
012.
objConn =
New
OleDbConnection(strConnString)
013.
objConn.Open()
014.
015.
BindData()
016.
End
Sub
017.
018.
Sub
BindData()
019.
Dim
strSQL
As
String
020.
strSQL =
"SELECT * FROM customer"
021.
022.
Dim
dtReader
As
OleDbDataReader
023.
objCmd =
New
OleDbCommand(strSQL, objConn)
024.
dtReader = objCmd.ExecuteReader()
025.
026.
027.
myGridView.DataSource = dtReader
028.
myGridView.DataBind()
029.
030.
dtReader.Close()
031.
dtReader =
Nothing
032.
033.
End
Sub
034.
035.
Sub
Page_UnLoad()
036.
objConn.Close()
037.
objConn =
Nothing
038.
End
Sub
039.
040.
Private
Sub
myGridView_RowDataBound(sender
As
Object
, e
As
GridViewRowEventArgs)
041.
042.
Dim
lblCustomerID
As
Label =
CType
(e.Row.FindControl(
"lblCustomerID"
),Label)
043.
IF
Not
IsNothing(lblCustomerID)
Then
044.
lblCustomerID.Text = e.Row.DataItem(
"CustomerID"
)
045.
End
IF
046.
047.
048.
Dim
lblName
As
Label =
CType
(e.Row.FindControl(
"lblName"
),Label)
049.
IF
Not
IsNothing(lblName)
Then
050.
lblName.Text = e.Row.DataItem(
"Name"
)
051.
End
IF
052.
053.
054.
Dim
lblEmail
As
Label =
CType
(e.Row.FindControl(
"lblEmail"
),Label)
055.
IF
Not
IsNothing(lblEmail)
Then
056.
lblEmail.Text = e.Row.DataItem(
"Email"
)
057.
End
IF
058.
059.
060.
Dim
lblCountryCode
As
Label =
CType
(e.Row.FindControl(
"lblCountryCode"
),Label)
061.
IF
Not
IsNothing(lblCountryCode)
Then
062.
lblCountryCode.Text = e.Row.DataItem(
"CountryCode"
)
063.
End
IF
064.
065.
066.
Dim
lblBudget
As
Label =
CType
(e.Row.FindControl(
"lblBudget"
),Label)
067.
IF
Not
IsNothing(lblBudget)
Then
068.
lblBudget.Text = FormatNumber(e.Row.DataItem(
"Budget"
),2)
069.
End
IF
070.
071.
072.
Dim
lblUsed
As
Label =
CType
(e.Row.FindControl(
"lblUsed"
),Label)
073.
IF
Not
IsNothing(lblUsed)
Then
074.
lblUsed.Text = FormatNumber(e.Row.DataItem(
"Used"
),2)
075.
End
IF
076.
077.
078.
Dim
lblExpDate
As
Label =
CType
(e.Row.FindControl(
"lblExpDate"
),Label)
079.
IF
Not
IsNothing(lblExpDate)
Then
080.
lblExpDate.Text = e.Row.DataItem(
"ExpireDate"
)
081.
IF
CDate
(e.Row.DataItem(
"ExpireDate"
)) =
CDate
(
Date
.Now())
Then
082.
lblExpDate.Text = lblExpDate.Text &
" - มีวัคซีนหมดอายุวันนี้"
083.
End
IF
084.
End
IF
085.
End
Sub
086.
087.
</script>
088.
<html>
089.
<head>
090.
<title>ThaiCreate.Com ASP.NET - GridView</title>
091.
</head>
092.
<body>
093.
<form id=
"form1"
runat=
"server"
>
094.
<asp:GridView id=
"myGridView"
runat=
"server"
AutoGenerateColumns=
"False"
onRowDataBound=
"myGridView_RowDataBound"
>
095.
096.
<Columns>
097.
098.
<asp:TemplateField HeaderText=
"CustomerID"
>
099.
<ItemTemplate>
100.
<asp:Label id=
"lblCustomerID"
runat=
"server"
></asp:Label>
101.
</ItemTemplate>
102.
</asp:TemplateField>
103.
104.
<asp:TemplateField HeaderText=
"Name"
>
105.
<ItemTemplate>
106.
<asp:Label id=
"lblName"
runat=
"server"
></asp:Label>
107.
</ItemTemplate>
108.
</asp:TemplateField>
109.
110.
<asp:TemplateField HeaderText=
"Email"
>
111.
<ItemTemplate>
112.
<asp:Label id=
"lblEmail"
runat=
"server"
></asp:Label>
113.
</ItemTemplate>
114.
</asp:TemplateField>
115.
116.
<asp:TemplateField HeaderText=
"CountryCode"
>
117.
<ItemTemplate>
118.
<asp:Label id=
"lblCountryCode"
runat=
"server"
></asp:Label>
119.
</ItemTemplate>
120.
</asp:TemplateField>
121.
122.
<asp:TemplateField HeaderText=
"Budget"
>
123.
<ItemTemplate>
124.
<asp:Label id=
"lblBudget"
runat=
"server"
></asp:Label>
125.
</ItemTemplate>
126.
</asp:TemplateField>
127.
128.
<asp:TemplateField HeaderText=
"Used"
>
129.
<ItemTemplate>
130.
<asp:Label id=
"lblUsed"
runat=
"server"
></asp:Label>
131.
</ItemTemplate>
132.
</asp:TemplateField>
133.
134.
<asp:TemplateField HeaderText=
"Expire Date"
>
135.
<ItemTemplate>
136.
<asp:Label id=
"lblExpDate"
runat=
"server"
></asp:Label>
137.
</ItemTemplate>
138.
</asp:TemplateField>
139.
140.
</Columns>
141.
</asp:GridView>
142.
</form>
143.
</body>
144.
</html>