<%@ Import Namespace="System.Data" %>
<html>
<head>
<title>FormView DataBound Event Example</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server">
void getImageUrl ( Object src, EventArgs e ) {
DataRowView dataRow = ( DataRowView ) categoryInfo.DataItem;
string catName = dataRow [ "CategoryName" ].ToString ( ).Replace ( "/", " " );
Image img = ( Image ) categoryInfo.FindControl ( "img" );
img.ImageUrl = string.Format ( "/shared/images/nwind/{0}.png", catName );
}
</script>
<body>
<!-- #include virtual="~/shared/top.inc" -->
<div class="header"><h2>FormView <span class="hilite">DataBound Event</span> Example</h2></div>
<hr size=1 width=92%>
<form runat="server">
<div align="center">
<asp:formview id="categoryInfo" runat="server"
datasourceid="categories"
width=80% cellpadding=5
backimageurl="~/shared/images/gradient-body.gif"
gridlines=horizontal
allowpaging
ondatabound="getImageUrl">
<headertemplate>
<div style="font-size:13pt; font-weight:bold; padding:5; background:darkslategray; color:khaki">
Northwind Product Categories
</div>
</headertemplate>
<itemtemplate>
<table>
<tr>
<td><asp:image id="img" runat="server"
title='<%# Eval ( "CategoryName" ) %>'
style="border: thin inset" /></td>
<td>
<table>
<col valign="top">
<col valign="top">
<tr>
<td align=right><b>Code:</b></td>
<td><asp:label runat="server" text='<%# Eval ( "CategoryID" ) %>' /></td>
</tr>
<tr>
<td align=right><b>Category:</b></td>
<td><asp:label runat="server" text='<%# Eval ( "CategoryName" ) %>' /></td>
</tr>
<tr>
<td align=right><b>Description:</b></td>
<td><asp:label runat="server" text='<%# Eval ( "Description" ) %>' /></td>
</tr>
</table>
</tr>
</table>
</itemtemplate>
</asp:formview>
<asp:sqldatasource id="categories" runat="server"
selectcommand="SELECT * FROM Categories"
connectionstring="<%$ ConnectionStrings:aspnet %>" />
</div>
</form>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>