<%@ Import Namespace="System.Data" %>
<html>
<head>
<title>Dynamically Generated HyperLinkColumn Images</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server">
public void getImages ( Object src, DataGridItemEventArgs e ) {
if ( e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem ) {
DataRowView rowView = ( DataRowView ) e.Item.DataItem;
string planId = rowView [ "PlanId" ].ToString ( );
TableCellCollection myCells = e.Item.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 ( );
}
}
void setPage ( Object src, DataGridPageChangedEventArgs e ) {
// set CurrentPageIndex to the page the user clicked.
myGrid.CurrentPageIndex = e.NewPageIndex;
// rebind the data
myGrid.DataBind ( );
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc" -->
<div class="header"><h2>Dynamically Generated HyperLinkColumn Images</h2></div>
<hr size=1 width=92%>
<div align="center">
<form runat="server">
<asp:datagrid id="myGrid" runat="server"
datasourceid="plans"
width=96% cellpadding=5 font-size="9pt"
gridlines="horizontal"
showheader=false
autogeneratecolumns=false
allowpaging pagesize=5
onItemDataBound="getImages"
onPageIndexChanged="setPage">
<itemstyle backcolor="ghostwhite" verticalalign="top" />
<pagerstyle
backcolor="darkslategray"
forecolor="khaki"
font-bold
horizontalalign="right"
position="topandbottom"
mode="numericpages"
nextpagetext="Next" prevpagetext="Prev" />
<columns>
<asp:boundcolumn
datafield="Design" />
<asp:boundcolumn
datafield="Model"
itemstyle-forecolor="navy"
itemstyle-font-size="10pt"
itemstyle-font-bold />
<asp:boundcolumn
datafield="Description" />
<asp:boundcolumn
datafield="PlanID"
itemstyle-horizontalalign="right" />
<asp:hyperlinkcolumn
datanavigateurlfield="planid"
datanavigateurlformatstring="plan_details.aspx?id={0}" />
</columns>
</asp:datagrid>
<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>