001.
<%@ Import Namespace=
"System.Data"
%>
002.
<%@ Import Namespace=
"System.Data.OleDb"
%>
003.
<%@ Page Language=
"C#"
Debug=
"true"
%>
004.
<script runat=
"server"
>
005.
006.
OleDbConnection objConn;
007.
OleDbCommand objCmd;
008.
009.
void
Page_Load(
object
sender,EventArgs e)
010.
{
011.
String strConnString;
012.
strConnString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+
013.
Server.MapPath(
"database/mydatabase.mdb"
) +
";"
;
014.
objConn =
new
OleDbConnection(strConnString);
015.
objConn.Open();
016.
017.
if
(!Page.IsPostBack)
018.
{
019.
BindData();
020.
}
021.
}
022.
023.
void
BindData()
024.
{
025.
String strSQL;
026.
strSQL =
"SELECT * FROM customer"
;
027.
028.
OleDbDataReader dtReader;
029.
objCmd =
new
OleDbCommand(strSQL, objConn);
030.
dtReader = objCmd.ExecuteReader();
031.
032.
033.
myRepeater.DataSource = dtReader;
034.
myRepeater.DataBind();
035.
036.
dtReader.Close();
037.
dtReader =
null
;
038.
039.
}
040.
041.
void
Page_UnLoad()
042.
{
043.
objConn.Close();
044.
objConn =
null
;
045.
}
046.
047.
protected
void
myRepeater_ItemDataBound(Object sender, RepeaterItemEventArgs e)
048.
{
049.
050.
051.
Label lblCustomerID = (Label)(e.Item.FindControl(
"lblCustomerID"
));
052.
if
(lblCustomerID !=
null
)
053.
{
054.
lblCustomerID.Text = (
string
)DataBinder.Eval(e.Item.DataItem,
"CustomerID"
);
055.
}
056.
057.
058.
Label lblName = (Label)(e.Item.FindControl(
"lblName"
));
059.
if
(lblName !=
null
)
060.
{
061.
lblName.Text = (
string
)DataBinder.Eval(e.Item.DataItem,
"Name"
);
062.
}
063.
064.
065.
Label lblEmail = (Label)(e.Item.FindControl(
"lblEmail"
));
066.
if
(lblEmail !=
null
)
067.
{
068.
lblEmail.Text = (
string
)DataBinder.Eval(e.Item.DataItem,
"Email"
);
069.
}
070.
071.
072.
Label lblCountryCode = (Label)(e.Item.FindControl(
"lblCountryCode"
));
073.
if
(lblCountryCode !=
null
)
074.
{
075.
lblCountryCode.Text = (
string
)DataBinder.Eval(e.Item.DataItem,
"CountryCode"
);
076.
}
077.
078.
079.
Label lblBudget = (Label)(e.Item.FindControl(
"lblBudget"
));
080.
if
(lblBudget !=
null
)
081.
{
082.
lblBudget.Text = DataBinder.Eval(e.Item.DataItem,
"Budget"
).ToString();
083.
}
084.
085.
086.
Label lblUsed = (Label)(e.Item.FindControl(
"lblUsed"
));
087.
if
(lblUsed !=
null
)
088.
{
089.
lblUsed.Text = DataBinder.Eval(e.Item.DataItem,
"Used"
).ToString();
090.
}
091.
092.
}
093.
094.
void
Button1_Click(
object
sender,EventArgs e)
095.
{
096.
CheckBox chkCusID;
097.
Label lblID;
098.
int
i;
099.
lblText.Text =
""
;
100.
for
( i = 0; i <= myRepeater.Items.Count - 1; i++)
101.
{
102.
chkCusID = (CheckBox)myRepeater.Items[i].FindControl(
"chkCustomerID"
);
103.
lblID = (Label)myRepeater.Items[i].FindControl(
"lblCustomerID"
);
104.
if
(chkCusID.Checked)
105.
{
106.
107.
this
.lblText.Text =
this
.lblText.Text +
"<br>"
+ lblID.Text;
108.
}
109.
}
110.
}
111.
112.
</script>
113.
<html>
114.
<head>
115.
<title>ThaiCreate.Com ASP.NET - Repeater</title>
116.
</head>
117.
<body>
118.
<form id=
"form1"
runat=
"server"
>
119.
<table border=
"1"
>
120.
<asp:Repeater id=
"myRepeater"
runat=
"server"
onItemDataBound=
"myRepeater_ItemDataBound"
>
121.
<HeaderTemplate>
122.
<tr>
123.
<th>Select</th>
124.
<th>CustomerID</th>
125.
<th>Name</th>
126.
<th>Email</th>
127.
<th>CountryCode</th>
128.
<th>Budget</th>
129.
<th>Used</th>
130.
</tr>
131.
</HeaderTemplate>
132.
<ItemTemplate>
133.
<tr>
134.
<td align=
"center"
><asp:CheckBox id=
"chkCustomerID"
runat=
"server"
></asp:CheckBox></td>
135.
<td align=
"center"
><asp:Label id=
"lblCustomerID"
runat=
"server"
></asp:Label></td>
136.
<td><asp:Label id=
"lblName"
runat=
"server"
></asp:Label></td>
137.
<td><asp:Label id=
"lblEmail"
runat=
"server"
></asp:Label></td>
138.
<td align=
"center"
><asp:Label id=
"lblCountryCode"
runat=
"server"
></asp:Label></td>
139.
<td align=
"right"
><asp:Label id=
"lblBudget"
runat=
"server"
></asp:Label></td>
140.
<td align=
"right"
><asp:Label id=
"lblUsed"
runat=
"server"
></asp:Label></td>
141.
</tr>
142.
</ItemTemplate>
143.
</asp:Repeater>
144.
</table>
145.
<br />
146.
<asp:Button id=
"Button1"
onclick=
"Button1_Click"
runat=
"server"
Text=
"Submit"
></asp:Button>
147.
<hr />
148.
<asp:Label id=
"lblText"
runat=
"server"
></asp:Label>
149.
</form>
150.
</body>
151.
</html>