<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<head>
<title>Repeater ItemCommand Event Example</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server" src="fetchData_sql.cs" />
<script language="C#" runat="server">
void Page_Load ( Object src, EventArgs e ) {
if ( !IsPostBack ) {
string query = "SELECT * FROM Shippers";
myRepeater.DataSource = fetchReader ( query );
myRepeater.DataBind ( );
}
}
void showItem ( Object src, RepeaterCommandEventArgs e ) {
items.Text = e.Item.ItemType.ToString ( ) + " " +
e.Item.ItemIndex.ToString ( ) + ", " +
( ( LinkButton ) e.CommandSource ).Text + "<br>";
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc" -->
<div class="header"><h2>Repeater ItemCommand Event Example</h2></div>
<hr size=1 width=92%>
<form runat="server">
<div align="center">
<asp:repeater id="myRepeater" runat="server" onItemCommand="showItem">
<headertemplate>
<table class="data" cellspacing=1>
<tr>
<th>ShipperID</th>
<th>Company Name</th>
<th>Phone</th>
</tr>
</headertemplate>
<itemtemplate>
<tr>
<td><%# Eval ( "ShipperID" ) %></td>
<td><asp:linkbutton runat="server"
text=<%# Eval ( "CompanyName" ) %> /></td>
<td><%# Eval ( "Phone" ) %></td>
</tr>
</itemtemplate>
<footertemplate>
</table>
</footertemplate>
</asp:repeater>
</div>
<p style="padding-left:10"><asp:label id="items" runat="server" />
</form>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>