<%@ Import Namespace="System.Data" %>
<html>
<head>
<title>Dynamically Generated HyperLinkField Images</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server">
public void getImages ( Object src, GridViewRowEventArgs e ) {
if ( e.Row.RowType == DataControlRowType.DataRow ) {
DataRowView rowView = ( DataRowView ) e.Row.DataItem;
string planId = rowView [ "PlanId" ].ToString ( );
TableCellCollection myCells = e.Row.Cells;
HyperLink planLink = ( HyperLink ) myCells [ myCells.Count - 1 ].Controls [ 0 ];
planLink.ImageUrl = string.Format ( "~/shared/images/plans/thumbs/{0}.jpg", planId );
planLink.ToolTip = rowView [ "Model" ].ToString ( );
}
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc" -->
<div class="header"><h2>Dynamically Generated HyperLinkField Images</h2></div>
<hr size=1 width=92%>
<div align="center">
<form runat="server">
<asp:gridview id="myGrid" runat="server"
datasourceid="plans"
width=98% cellpadding=5 font-size="9pt"
gridlines="horizontal"
showheader=false
autogeneratecolumns=false
allowpaging pagesize=5
onRowDataBound="getImages">
<rowstyle backcolor="ghostwhite" verticalalign="top" />
<pagersettings
position="topandbottom"
mode="numericfirstlast"
nextpagetext="Next" previouspagetext="Prev" />
<pagerstyle
backcolor="darkslategray"
forecolor="khaki"
font-bold
horizontalalign="right" />
<columns>
<asp:boundfield
datafield="Design" />
<asp:boundfield
datafield="Model"
itemstyle-forecolor="navy"
itemstyle-font-size="10pt"
itemstyle-font-bold />
<asp:boundfield
datafield="Description" />
<asp:boundfield
datafield="PlanID"
itemstyle-horizontalalign="right" />
<asp:hyperlinkfield
datanavigateurlfields="planid"
datanavigateurlformatstring="plan_details.aspx?id={0}">
<controlstyle borderwidth=1 borderstyle="inset" />
</asp:hyperlinkfield>
</columns>
</asp:gridview>
<asp:accessdatasource id="plans" runat="server"
datafile="~/app_data/plans.mdb"
selectcommand="SELECT Design, Model, Description, PlanId FROM Plans
WHERE Type in ( 'English', 'French', 'Tudor', 'Victorian' )" />
</form>
</div>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>