<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<head>
<title>DataList 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 Employees";
myDataList.DataSource = fetchData ( query );
myDataList.DataBind ( );
}
}
void showItem ( Object src, DataListCommandEventArgs e ) {
myDataList.SelectedIndex = e.Item.ItemIndex;
string query = "SELECT * FROM Employees";
myDataList.DataSource = fetchData ( query );
myDataList.DataBind ( );
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc" -->
<div class="header"><h2>DataList ItemCommand Event Example</h2></div>
<hr size=1 width=92%>
<div align="center">
<form runat="server">
<asp:datalist id="myDataList" runat="server"
width="92%" cellpadding=5 repeatcolumns=3
backcolor="ghostwhite"
headerstyle-backcolor="lightsteelblue"
headerstyle-font-bold
itemstyle-verticalalign="top"
selecteditemstyle-backcolor="khaki"
onItemCommand="showItem">
<headertemplate>
NorthWind Traders Employees
</headertemplate>
<itemtemplate>
<asp:linkbutton runat="server"
text='<%# Eval ( "LastName" ) %>' />
</itemtemplate>
<selecteditemtemplate>
<img align="right" width=75 runat="server"
src='<%# Eval ( "LastName",
"~/shared/images/{0}.jpg" ) %>' />
<b><%# Eval ( "FirstName" ) %>
<%# Eval ( "LastName" ) %></b><br>
<%# Eval ( "Title" ) %><br>
<%# Eval ( "Address" ) %>,
<%# Eval ( "City" ) %>
</selecteditemtemplate>
</asp:datalist>
</form>
</div>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc -->
</body>
</html>