<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.IO" %><html><head>
<title>Employees</title>
<style>
  hr {height:2px;color:black;}
  .StdText {font-family:verdana;font-size:9pt;}
  .StdTextBox {font-family:verdana;font-size:9pt;border:solid 1px black;filter:progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true');}
</style> <SCRIPT runat="server"> 
public void Page_Load(Object sender, EventArgs e)
{
if (!IsPostBack) {
lblURL.Text = Request.Url + "<hr>";
}
}public void OnSearch(Object sender, EventArgs e)
{
DataSet ds = new DataSet(); String sConn = "server=localhost;uid=sa;Initial Catalog=Northwind;";
String sText = "SELECT employeeid, firstname, lastname FROM Employees ";
sText += "WHERE employeeid >=" + tbEmpID.Text;
SqlDataAdapter cmd = new SqlDataAdapter(sText, sConn);
cmd.Fill(ds, "EmpTable"); DataList1.DataSource = ds.Tables["EmpTable"].DefaultView;
DataList1.DataBind(); theLabel.Visible = true;
theLabel.Text = "Click to read more.";
}void HandleSelection(Object sender, EventArgs e)
{
int nEmpID = (int) DataList1.DataKeys[DataList1.SelectedIndex]; String sConn = "server=localhost;uid=sa;Initial Catalog=Northwind;";
SqlConnection cn = new SqlConnection(sConn); String sText = "SELECT title, hiredate, country, notes FROM Employees ";
sText += "WHERE employeeid = " + nEmpID.ToString();
SqlCommand cmd = new SqlCommand(sText, cn);
cn.Open(); SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
theLabel.Text =  "<b>" + dr["title"] + "</b><br>"; 
DateTime dt = Convert.ToDateTime(dr["hiredate"]);
theLabel.Text += "Hired on " + dt.ToShortDateString() + " from " + dr["country"] + "<hr>"; 
theLabel.Text += "<i>" + dr["Notes"] + "</i>";  btnUnselect.Visible = true;
dr.Close();
cn.Close();
}void RemoveSelection(Object sender, EventArgs e)
{
DataList1.SelectedIndex = -1;
theLabel.Text = "Click to read more.";
btnUnselect.Visible = false;
}</SCRIPT> <body bgcolor="ivory" style="font-family:arial;font-size:9pt">
<h2>Employees</h2>
 
<!-- ASP.NET Form -->
<form runat="server"><asp:Label runat="server" cssclass="StdText" font-bold="true">Current path: </asp:label>
<asp:Label runat="server" id="lblURL" cssclass="StdText" style="color:blue"></asp:label><table border="0"><tr>
<td><asp:Label runat="server" cssclass="StdText" font-bold="true">EmployeeID</asp:label></td>
<td><asp:textbox runat="server" id="tbEmpID" cssclass="StdTextBox" width="100px">1</asp:textbox></td>
<td><asp:LinkButton runat="server" cssclass="StdText" Text="Search" onclick="OnSearch" ></asp:LinkButton></td>
</tr>
</table><hr>
<br><table><tr><td valign="top"><asp:DataList runat="server" id="DataList1" DataKeyField="employeeid" 
OnSelectedIndexChanged="HandleSelection"><SelectedItemStyle BackColor="lightblue" />
<HeaderTemplate>
   <h3>Northwind's Employees</h3>
</HeaderTemplate><ItemTemplate>
  <asp:linkbutton runat="server" commandname="select"
Text='<%# ((DataRowView)Container.DataItem)["employeeid"] + " - " +             
                  ((DataRowView)Container.DataItem)["lastname"]  + ", " +
                  ((DataRowView)Container.DataItem)["firstname"] %> ' />
  
</ItemTemplate><FooterTemplate>
   <hr>
</FooterTemplate></asp:DataList>   <asp:linkbutton runat="server" id="btnUnselect" 
Visible="false"
OnClick="RemoveSelection" Text="Unselect" />
</td>
<td width=100px></td>
<td width=300px valign="top" ><asp:label runat="server" id="theLabel" Visible="false"></asp:label> 
<br></td></tr></table><!-- End of ASP.NET page -->
</form> </body>
</html>