<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<html>
<title>Responding to Changes in a DropDownList Control</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<style>
<!--
.orderID {font:bold 9pt arial; color:navy}
-->
</style>
<script language="C#" runat="server" src="fetchData_oledb.cs"></script>
<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 getGear ( object src, EventArgs e ) {
string query = "SELECT ProductType, ProductCode, ProductName, " +
"ProductDescription, ProductImageURL, UnitPrice FROM Products " +
"where ProductType='" + mySelect.SelectedItem.Text + "'";
myList.DataSource = fetchData ( query, "dbtutor" );
myList.DataBind ( );
}
</script>
<body>
<div class="header"><h2>Responding to Changes in a DropDownList Control</h2></div><hr size=1 width=92%>
<div align="center">
<form runat="server">
<p>Select Type of Gear: <asp:dropdownlist id="mySelect"
datatextfield="ProductType"
onSelectedIndexChanged="getGear"
autopostback runat="server" />
<p>
<asp:datalist id="myList" 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" ) %> <%# 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>