<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<html>
<head>
<title>Populating an HtmlSelect Control from a Database</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<style>
.orderID {font:bold italic arial; color:darkcyan}
</style>
<script language="C#" runat="server" src="fetchData_oledb.cs" />
<script language="C#" runat="server">
protected void Page_Load ( object src, EventArgs e ) {
if ( !IsPostBack ) {
string query = "SELECT DISTINCT ProductType FROM Products";
mySelect.DataSource = fetchData ( query, "dbtutor" );
mySelect.DataBind ( );
}
}
public void getProducts ( object src, EventArgs e ) {
string query = "SELECT ProductCode, ProductName, ProductDescription, ProductImageURL, UnitPrice FROM Products WHERE ProductType='" +
mySelect.Value + "'";
myDataList.DataSource = fetchData ( query, "dbtutor" );
myDataList.DataBind ( );
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc -->
<div class="header"><h2>Populating an HtmlSelect Control from a Database</h2></div>
<!-- #include virtual="~/shared/viewsrc_top.inc" -->
<hr size=1 width=92%>
<div align="center">
<form runat="server">
<p>Select Gear: <select id="mySelect" datatextfield="ProductType" runat="server" />
<input type=submit onServerClick="getProducts" value="Get Gear" runat="server" />
<asp:datalist id="myDataList" repeatcolumns=2 runat="server">
<itemtemplate>
<table cellpadding=10>
<tr valign="top">
<td><img align="top"
src='<%# Eval ( "ProductImageURL" ) %>' >
</td>
<td>
<b><%# Eval ( "ProductName" ) %></b>
<br>
<%# Eval ( "ProductDescription" ) %>
<p class="orderID">Code: <%# Eval ( "ProductCode" ) %>
<br>
US<%# Eval ( "UnitPrice", "{0:c2}" ) %></p>
</td></tr>
</table>
</itemtemplate>
<footertemplate>
<div align="center"><hr size=1 width=92%><small>Catalog photos courtesy of Recreational Equipment Incorporated.<br>© <%= DateTime.Now.Year %> Reynald Nuñez and Adventure Works</small></div>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</footertemplate>
</asp:datalist>
</form>
</div>
</body>
</html>