<%@ Import Namespace="System.Data" %>
<html>
<head>
<title>Dynamically Generated ButtonField ImageButtons</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<style type="text/css">
.desc {
font:bold 11pt arial,verdana,sans-serif; background:whitesmoke;
border:1px inset; padding:10; margin-bottom:10}
.specs {
font-size:9pt; background:beige;
border:1px inset; padding-right:5}
</style>
<script language="C#" runat="server">
void Page_Load ( Object src, EventArgs e ) {
if ( !IsPostBack ) {
productsList.SelectedIndex = 0;
productsList.DataBind ( );
productDetails.DataBind ( );
}
}
public void getImages ( Object src, GridViewRowEventArgs e ) {
if ( e.Row.RowType == DataControlRowType.DataRow ) {
DataRowView rowView = ( DataRowView ) e.Row.DataItem;
string productId = rowView [ "productid" ].ToString ( );
ImageButton imgButton = ( ImageButton ) e.Row.Cells [ 0 ].Controls [ 0 ];
imgButton.ImageUrl = string.Format ( "~/shared/images/gear/{0}.jpg", productId );
}
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc" -->
<div class="header"><h2>Dynamically Generated ButtonField ImageButtons</h2></div>
<hr size=1 width=92%>
<form runat="server">
<center>
<table width="96%">
<tr valign="top">
<td width=50%>
<asp:gridview id="productsList" runat="server"
datasourceid="products"
datakeynames="productid"
autogeneratecolumns=false
allowpaging pagesize=5
cellpadding=5 font-size="9pt"
gridlines="horizontal"
onRowDataBound="getImages">
<headerstyle backcolor="steelblue"
forecolor="beige" />
<rowstyle verticalalign="top" />
<columns>
<asp:buttonfield
buttontype="image"
commandname="select">
<controlstyle width=75
borderwidth=1 borderstyle="inset" />
</asp:buttonfield>
<asp:templatefield>
<itemtemplate>
<table>
<tr>
<td>Item:</td>
<td><asp:linkbutton runat="server"
text='<%# Eval ( "ProductName" ) %>'
commandname="select" style="color:navy" /></td></tr>
<tr>
<td>Price:</td>
<td><%# Eval ( "Price", "{0:c}" ) %></td></tr>
</table>
</itemtemplate>
</asp:templatefield>
</columns>
<selectedrowstyle backcolor="palegoldenrod" />
</asp:gridview>
</td>
<td>
<asp:formview id="productDetails" runat="server"
datasourceid="details"
enableviewstate=false>
<itemtemplate>
<img runat="server"
src='<%# Eval ( "ProductID", "~/shared/images/gear/{0}.jpg" ) %>'
alt='<%# Eval ( "Model" ) %>'
width=220 height=220 border=0>
<br>
<div class="desc">
<%# Eval ( "Description" ) %>
</div>
<div class="specs">
<%# Eval ( "Specs" ) %>
</div>
</itemtemplate>
</asp:formview>
</td></tr>
</table>
<asp:accessdatasource id="products" runat="server"
datafile="~/app_data/gear.mdb"
selectcommand="SELECT ProductId, Brand + ' ' + Model AS ProductName, Price FROM Products
WHERE Type='Stove'" />
<asp:accessdatasource id="details" runat="server"
datafile="~/app_data/gear.mdb"
selectcommand="SELECT * FROM Products"
filterexpression="ProductId='{0}'">
<filterparameters>
<asp:controlparameter controlid="productsList" propertyname="SelectedValue" />
</filterparameters>
</asp:accessdatasource>
</center>
</form>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>