<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<title>Dynamically Generated ImageButtons</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server" src="fetchData_sql.cs" />
<script language="C#" runat="server">
void Page_Load ( object src, EventArgs e ) {
if ( !IsPostBack ) {
string query = "SELECT * FROM Titles WHERE Type = 'psychology'";
myList.DataSource = fetchData ( query );
myList.DataBind ( );
}
}
void getDetails ( object src, EventArgs e ) {
string title = myList.DataKeys [ myList.SelectedIndex ].ToString ( );
string query = "SELECT * FROM Titles WHERE Title_id = '" + title + "'";
myDetailsList.DataSource = fetchData ( query );
myDetailsList.DataBind ( );
}
</script>
<body>
<!-- #include virtual="~/shared/top.inc -->
<div class="header"><h2>Dynamically Generated ImageButtons</h2></div>
<!-- #include virtual="~/shared/viewsrc_top.inc" -->
<hr size=1 width=92%>
<form runat="server">
<table width="100%">
<tr valign="top">
<td width="50%">
<asp:datalist id="myList" runat="server"
datakeyfield="title_id"
onSelectedIndexChanged="getDetails" >
<itemtemplate>
<table cellpadding=8>
<tr>
<td valign="top">
<asp:imagebutton width=30 alt="Click for details"
imageurl='<%# Eval ( "title_id",
"~/shared/images/title-{0}.gif" ) %>'
commandname="Select"
borderstyle="solid" borderwidth=1
runat="server" />
</td>
<td valign="top">
<b>Title:</b> <asp:linkbutton
text='<%# Eval ( "title" ) %>'
commandname="Select"
style="color:darkred"
runat="server" />
<br>
<b>Price:</b> <%# Eval ( "Price", "{0:c}" ) %>
</td></tr>
</table>
</itemtemplate>
</asp:datalist>
</td>
<td>
<asp:datalist id="myDetailsList" runat="server"
width="95%"
cellpadding=8
repeatcolumns=2
enableviewstate=false>
<itemtemplate>
<img align="top" border=1 src='<%# Eval ( "title_id", "~/shared/images/title-{0}.gif" ) %>' runat="server" />
<p style="font:bold 12pt arial; margin-bottom:5">
<i><%# Eval ( "title" ) %></i>
</p>
<b>Product Code:</b> <%# Eval ( "title_id" ) %><br>
<b>Category:</b> <%# Eval ( "type" ) %><br>
<p><b>Description:</b> <%# Eval ( "notes" ) %></p>
<b>Price:</b> <%# Eval ( "Price", "{0:c}" ) %>
</itemtemplate>
</asp:datalist>
</td></tr>
</table>
</form>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>