01.
<%@ Page Language=
"C#"
Debug=
"true"
%>
02.
<script runat=
"server"
>
03.
AccessDataSource myDSource;
04.
string
strSQL;
05.
void
Page_Load(
object
sender, EventArgs e)
06.
{
07.
08.
myDSource =
new
AccessDataSource();
09.
myDSource.DataFile =
"~/database/mydatabase.mdb"
;
10.
11.
if
(!Page.IsPostBack) {
12.
BindData();
13.
}
14.
}
15.
16.
void
BindData()
17.
{
18.
19.
myDSource.SelectCommand =
"SELECT * FROM [customer]"
;
20.
21.
22.
myGridView.DataSource = myDSource;
23.
myGridView.DataBind();
24.
25.
myDSource =
null
;
26.
27.
}
28.
</script>
29.
<html>
30.
<head>
31.
<title>ThaiCreate.Com ASP.NET - AccessDataSource</title>
32.
</head>
33.
<body>
34.
<form id=
"form1"
runat=
"server"
>
35.
<asp:GridView id=
"myGridView"
runat=
"server"
AutoGenerateColumns=
"False"
>
36.
<Columns>
37.
<asp:TemplateField HeaderText=
"CustomerID"
>
38.
<ItemTemplate>
39.
<asp:Label id=
"lblCustomerID"
runat=
"server"
Text=
'<%# DataBinder.Eval(Container, "DataItem.CustomerID") %>'
></asp:Label>
40.
</ItemTemplate>
41.
</asp:TemplateField>
42.
43.
<asp:TemplateField HeaderText=
"Name"
>
44.
<ItemTemplate>
45.
<asp:Label id=
"lblName"
runat=
"server"
Text=
'<%# DataBinder.Eval(Container, "DataItem.Name") %>'
></asp:Label>
46.
</ItemTemplate>
47.
</asp:TemplateField>
48.
49.
<asp:TemplateField HeaderText=
"Email"
>
50.
<ItemTemplate>
51.
<asp:Label id=
"lblEmail"
runat=
"server"
Text=
'<%# DataBinder.Eval(Container, "DataItem.Email") %>'
></asp:Label>
52.
</ItemTemplate>
53.
</asp:TemplateField>
54.
55.
<asp:TemplateField HeaderText=
"CountryCode"
>
56.
<ItemTemplate>
57.
<asp:Label id=
"lblCountryCode"
runat=
"server"
Text=
'<%# DataBinder.Eval(Container, "DataItem.CountryCode") %>'
></asp:Label>
58.
</ItemTemplate>
59.
</asp:TemplateField>
60.
61.
<asp:TemplateField HeaderText=
"Budget"
>
62.
<ItemTemplate>
63.
<asp:Label id=
"lblBudget"
runat=
"server"
Text=
'<%# DataBinder.Eval(Container, "DataItem.Budget") %>'
></asp:Label>
64.
</ItemTemplate>
65.
</asp:TemplateField>
66.
67.
<asp:TemplateField HeaderText=
"Used"
>
68.
<ItemTemplate>
69.
<asp:Label id=
"lblUsed"
runat=
"server"
Text=
'<%# DataBinder.Eval(Container, "DataItem.Used") %>'
></asp:Label>
70.
</ItemTemplate>
71.
</asp:TemplateField>
72.
</Columns>
73.
</asp:GridView>
74.
</form>
75.
</body>
76.
</html>