<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<title>Introduction to Templated Controls ( DataList )</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" src="~/shared/fetchData_sql.cs" runat="server" />
<script language="C#" runat="server">
void Page_Load ( Object sender, EventArgs e ) {
if ( !IsPostBack ) {
string query = "SELECT DISTINCT Publisher FROM Books WHERE Price IS NOT NULL";
lstPubs.DataSource = fetchReader ( query );
lstPubs.DataBind ( );
//initialize selection
lstPubs.SelectedIndex = 1;
getBooks ( null, null );
}
}
void getBooks ( Object sender, EventArgs e ) {
string poblisher = lstPubs.Text;
string query = "SELECT * FROM Books WHERE Publisher = '" + poblisher + "' AND Price IS NOT NULL";
myList.DataSource = fetchReader ( query );
myList.DataBind ( );
}
</script>
<body topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>
<!-- #include file="dl_header.inc" -->
<center>
<form runat="server">
<p>Select Publisher: <asp:dropdownlist id="lstPubs" runat="server"
autopostback onSelectedIndexChanged="getBooks"
datatextfield="Publisher" /></p>
<asp:datalist id="myList" runat="server" width=90%
repeatcolumns=2 repeatdirection="horizontal"
itemstyle-width=50%>
<itemtemplate>
<table width=92% align="center" cellpadding=10>
<tr>
<td width=25% valign="top">
<a href='<%# Eval ( "titleid", "https://www.amazon.com/dp/{0}?&tag=rvnunz0525-20" ) %>'
target="_blank"><img src='<%# Eval ( "titleid", "/shared/books/{0}.jpg" ) %>'
style="box-shadow: 3px 3px 3px gray"></a>
</td>
<td width=75% valign="top">
<p style="font:bold 14pt arial">
<a href='<%# Eval ( "titleid", "https://www.amazon.com/dp/{0}?&tag=rvnunz0525-20" ) %>'
target="_blank"><span style="color:darkgreen"><%# Eval ( "title" )%></span></a></p>
<b>Title ID:</b> <%# Eval ( "titleid" ) %><br>
<b>Author:</b> <%# Eval ( "author" ) %><br>
<b>Category:</b> <%# Eval ( "subject" ) %><br>
<b>Publisher:</b> <%# Eval ( "publisher" ) %><br>
<b>Price (from):</b> <%# Eval ( "price", "{0:c2}" ) %><p>
</td></tr>
</table>
</itemtemplate>
</asp:datalist>
</form>
</center>
<!-- #include file="dl_footer.inc" -->
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>