@ import namespace="system.data" %>
<%@ import namespace="system.data.sqlclient" %>
<html>
<script language="c#" runat="server">
sqlconnection myconnection;
void page_load(object sender, eventargs e) {
myconnection = new sqlconnection("server=(local)\\netsdk;database=pubs;trusted_connection=yes");
sqldataadapter mycommand = new sqldataadapter("select * from titles where type = business", myconnection);
dataset ds = new dataset();
mycommand.fill(ds, "titles");
mydatalist.datasource=ds.tables["titles"].defaultview;
if (!page.ispostback) {
mydatalist.databind();
}
}
void mydatalist_select(object sender, eventargs e) {
string title = mydatalist.datakeys[mydatalist.selecteditem.itemindex].tostring();
sqldataadapter mycommand = new sqldataadapter("select * from titles where title_id = " + title + "" , myconnection);
dataset ds = new dataset();
mycommand.fill(ds, "titledetails");
datarowview rowview = ds.tables["titledetails"].defaultview[0];
detailsimage.src = "/quickstart/aspplus/images/title-" + rowview["title_id"] + ".gif";
detailspubid.text = "<b>publisher id: </b>" + rowview["pub_id"].tostring() + "<br>";
detailstitleid.text = "<b>title id: </b>" + rowview["title_id"].tostring() + "<br>";
detailstype.text = "<b>category: </b>" + rowview["type"].tostring() + "<br>";
detailsprice.text = "<b>price: </b> $ " + rowview["price"].tostring() + "<p>";
purchaselink.text = "<img border=0 src=/quickstart/aspplus/images/purchase_book.gif >";
purchaselink.navigateurl ="purchase.aspx?titleid=" + rowview["title_id"].tostring();
detailstitle.text = rowview["title"].tostring();
detailsimage.visible = true;
mydatalist.databind();
}
void mydatalist_itemcommand(object sender, datalistcommandeventargs e) {
string title = mydatalist.datakeys[e.item.itemindex].tostring();
string command = ((linkbutton)e.commandsource).text;
switch(command) {
case "discussions" :
showdiscussions(title);
break;
case "ratings" :
showratings(title);
break;
}
}
void showratings(string title) {
message.innerhtml = "<h5>ratings for \"" + title + "\"</h5>";
message.innerhtml += "todo: print ratings here…";
}
void showdiscussions(string title) {
message.innerhtml = "<h5>discussions for \"" + title + "\"</h5>";
message.innerhtml += "todo: print discussions here…";
}
</script>
<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">
<form runat="server">
<!– #include virtual="/quickstart/aspplus/samples/webforms/customize/header.inc" –>
<table width="100%">
<tr>
<td width="50%">
<asp:datalist id="mydatalist" onselectedindexchanged="mydatalist_select" onitemcommand="mydatalist_itemcommand" datakeyfield="title_id" runat="server">
<itemtemplate>
<table cellpadding=10 style="font: 10pt verdana">
<tr>
<td valign="top">
<img align="top" width="25" border=1 src=<%# databinder.eval(container.dataitem, "title_id", "/quickstart/aspplus/images/title-{0}.gif") %> runat="server"/>
</td>
<td valign="top">
<b>title: </b>
<asp:linkbutton text=<%# databinder.eval(container.dataitem, "title") %> commandname="select" style="color:darkred" runat="server"/>
<br>
<b>price: </b><%# databinder.eval(container.dataitem, "price", "$ {0}") %>
<br>
<asp:linkbutton text="discussions" commandname="discuss" style="color:darkred;font:8pt tahoma" runat="server"/>
|
<asp:linkbutton text="ratings" commandname="ratings" style="color:darkred;font:8pt tahoma" runat="server"/>
</td>
</tr>
</table>
</itemtemplate>
<selecteditemtemplate>
<table cellpadding=10 style="font: 10pt verdana" >
<tr>
<td valign="top">
<img src=<%# databinder.eval(container.dataitem, "title_id", "/quickstart/aspplus/images/title-{0}.gif") %> align="top" width="25" border=1 runat="server"/>
</td>
<td valign="top">
<b>title: </b>
<asp:linkbutton font-bold="true" text=<%# databinder.eval(container.dataitem, "title") %> commandname="select" style="color:darkred" runat="server"/>
<br>
<b>price: </b><%# databinder.eval(container.dataitem, "price", "$ {0}") %>
<br>
<asp:linkbutton text="discussions" commandname="discuss" style="color:darkred;font:8pt tahoma" runat="server"/>
|
<asp:linkbutton text="ratings" commandname="ratings" style="color:darkred;font:8pt tahoma" runat="server"/>
</td>
</tr>
</table>
</selecteditemtemplate>
</asp:datalist>
</td>
<td valign="top" style="padding-top:15" width="50%">
<table cellpadding="5" width="100%" style="font: 10pt verdana">
<tr>
<td>
<img id="detailsimage" visible="false" runat="server">
</td>
<td valign="top" width="400">
<div style="font: 12pt verdana;color:darkred">
<i><b><asp:label id="detailstitle" runat="server"/></i></b><br>
</div>
<asp:label id="detailstitleid" runat="server"/>
<asp:label id="detailspubid" runat="server"/>
<asp:label id="detailstype" runat="server"/>
<asp:label id="detailsprice" runat="server"/>
<asp:hyperlink id="purchaselink" runat="server"/>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!– #include virtual="/quickstart/aspplus/samples/webforms/customize/footer.inc" –>
<div id="message" style="font: 10pt verdana;padding:0,15,15,15" runat="server"/>
</form>
</body>
</html>
