<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<html>
<head>
<title>Binding a Variable Select Query to a DataList Control ( OleDb )</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server" src="fetchData_oledb.cs" />
<script runat="server">
protected void Page_Load ( object src, EventArgs e ) {
if ( !IsPostBack ) {
string query = "SELECT DISTINCT Type FROM Products";
mySelect.DataSource = fetchReader ( query, "gear" );
mySelect.DataBind ( );
}
}
public void getProducts ( object src, EventArgs e ) {
string query = "SELECT ProductId, Brand, Model, Description, Price FROM Products WHERE Type='" + mySelect.Value + "'";
myDataList.DataSource = fetchReader ( query, "gear" );
myDataList.DataBind ( );
}
</script>
<style type="text/css">
td a:link, td a:visited {
font:bold 9pt; color:slategray}
td a:hover {
color:navy; text-decoration:none}
.desc {
font:9pt;}
.price {
font:bold 9pt; color:#500}
</style>
</head>
<body>
<!-- #include virtual="~/shared/top.inc -->
<div class="header"><h2>Binding a <b>Variable Select Query</b> to a DataList Control</h2></div>
<!-- #include virtual="~/shared/viewsrc_top.inc" -->
<hr size=1 width=92%>
<center>
<form runat="server">
<p>Select Gear: <select id="mySelect" datatextfield="Type" runat="server" />
<input type=submit value="Get Gear"
onServerClick="getProducts" runat="server" />
<p>
<asp:datalist id="myDataList" runat="server"
width=90% repeatcolumns=2
enableviewstate=false
itemstyle-width=50%
itemstyle-verticalalign="top">
<itemtemplate>
<table cellpadding=10>
<tr valign="top">
<td>
<a href='<%# Eval ( "ProductID", "details_gear.aspx?id={0}" ) %>'>
<img width=75 border=0 runat="server"
alt='<%# Eval ( "Model" ) %>'
src='<%# Eval ( "ProductID", "~/shared/images/gear/{0}.jpg" ) %>' /></a>
</td>
<td>
<p style="margin-bottom:8">
<a href='<%# Eval ( "ProductID", "details_gear.aspx?id={0}" ) %>'>
<%# Eval ( "Brand" ) %> <%# Eval ( "Model" ) %>
</a>
</p>
<span class="desc"><%# Eval ( "Description" ) %></span><br>
<span class="price">Stock:
<%# Eval ( "ProductID" ) %> US<%# Eval ( "Price", "{0:c2}" ) %></span>
</td></tr>
</table>
</itemtemplate>
</asp:datalist>
</form>
</center>
<% if ( Request.Form [ "mySelect" ] != null ) {%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
<% } %>
</body>
</html>