<%@ Page Language="C#" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server" language="C#">
void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
BindData();
}
void BindData()
{
const string strConnString = "server=localhost;uid=sa;pwd=;database=pubs";
SqlConnection objConn = new SqlConnection(strConnString);
const string strSQL = "SELECT * FROM titles";
SqlCommand objCmd = new SqlCommand(strSQL, objConn);
objConn.Open();
dlTitles.DataSource = objCmd.ExecuteReader(CommandBehavior.CloseConnection);
dlTitles.DataBind();
objConn.Close();
}
void DisplayBookDetails(object sender, EventArgs e)
{
BindData();
}
</script>
<form runat="server">
<asp:DataList runat="server"
id="dlTitles"
OnSelectedIndexChanged="DisplayBookDetails"
Font-Name="Verdana"
Font-Size="11pt"
ItemStyle-BackColor="#eeeeee"
AlternatingItemStyle-BackColor="White"
HorizontalAlign="Center" CellPadding="8">
<ItemTemplate>
<i><%# DataBinder.Eval(Container.DataItem, "title") %></i>
[<asp:LinkButton
runat="server" CommandName="Select"
Text="View Book Details" />]
</ItemTemplate>
<SelectedItemTemplate>
<table>
<tr>
<td><b>Title:</b></td>
<td><%# DataBinder.Eval(Container.DataItem, "title") %></td>
</tr>
<tr>
<td><b>Type:</b></td>
<td><%# DataBinder.Eval(Container.DataItem, "type") %></td>
</tr>
<tr>
<td><b>Notes:</b></td>
<td><%# DataBinder.Eval(Container.DataItem, "notes") %></td>
</tr>
</table>
</SelectedItemTemplate>
</asp:DataList>
</form>
|