<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<head>
<title>Binding a BulletedList to a Data Source Control</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<style type="text/css">
<!--
tr {
vertical-align:top}
.title {
font:bold 13pt; padding:5;
background:teal; color:ivory}
.empname {
font:bold 13pt; padding:5;
background:navy; color:khaki}
.notes {
background-color:ghostwhite;
padding:10; border:1px inset}
-->
</style>
<script language="C#" runat="server" src="fetchdata_sql.cs" />
<script runat="server">
void getSelected ( Object src, BulletedListEventArgs e ) {
string empId = ( ( ListItem ) employeesList.Items [ e.Index ] ).Value;
employeeDetails.DataSource = fetchData (
"SELECT * FROM Employees WHERE EmployeeID = '" + empId + "'" );
employeeDetails.DataBind ( );
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc" -->
<div class="header"><h2>Binding a <span class="hilite">BulletedList</span> to a <span class="hilite">Data Source Control</span></h2></div>
<hr size=1 width=92%>
<form runat="server">
<table width=90% align="center" cellpadding=5>
<col width=20%>
<col width=80% align="center">
<tr>
<td valign="top">
<asp:bulletedlist id="employeesList" runat="server"
datasourceid="employees"
datatextfield="LastName"
datavaluefield="EmployeeID"
displaymode="linkbutton"
onclick="getSelected" />
</td>
<td valign="top">
<asp:formview id="employeeDetails" runat="server"
width=100% cellpadding=5>
<itemtemplate>
<table cellpadding=10 width="100%" align="center" bgcolor="whitesmoke">
<tr>
<td>
<img align="top" runat="server" border=0
src='<%# Eval ( "photopath", "~/shared/images/{0}" ) %>' />
</td>
<td>
<table cellpadding=5>
<tr>
<td colspan=2><div class="empname" runat="server">
<%# Eval ( "firstname" ) %>
<%# Eval ( "lastname" ) %>
</div></td>
</tr>
<tr>
<td>
<b>Title:</b> <%# Eval ( "title" ) %><br>
<b>Hire Date:</b> <%# Eval ( "hiredate", "{0:d}" ) %><br>
<b>Extension:</b> <%# Eval ( "extension" ) %></td>
</tr>
<tr>
<td>
<div class="notes">
<%# Eval ( "notes" ) %>
</div>
</td>
</tr>
</table>
</td></tr>
</table>
</itemtemplate>
</asp:formview>
</td>
</tr>
</table>
<asp:sqldatasource id="employees" runat="server"
SelectCommand="SELECT LastName, EmployeeID FROM employees"
connectionstring="<%$ ConnectionStrings:aspnet %>" />
</form>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>