<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<head>
<title>DataGrid TemplateColumn Example</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server" src="fetchData_sql.cs" />
<script language="C#" runat="server">
void Page_Load ( Object src, EventArgs e ) {
if ( !IsPostBack ) {
string query = "SELECT * FROM Titles";
myGrid.DataSource = fetchData ( query );
myGrid.DataBind ( );
}
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc" -->
<div class="header"><h2>DataGrid TemplateColumn Example</h2></div>
<hr size=1 width=92%>
<p align="center">
<asp:datagrid id="myGrid" runat="server"
width="92%" cellpadding=5 font-size="9pt"
gridlines="horizontal"
headerstyle-backcolor="slategray"
headerstyle-forecolor="ivory"
headerstyle-font-bold
itemstyle-verticalalign="top"
autogeneratecolumns=false>
<columns>
<asp:templatecolumn>
<itemtemplate>
<img width=60 align="top"
src='<%# Eval ( "title_id", "/shared/images/title-{0}.gif" ) %>' >
</itemtemplate>
</asp:templatecolumn>
<asp:boundcolumn headertext="Title"
datafield="title" />
<asp:boundcolumn headertext="Notes"
datafield="notes" />
<asp:boundcolumn headertext="Publication"
datafield="pubdate"
dataformatstring="{0:d}" />
<asp:boundcolumn headertext="Price"
datafield="price"
dataformatstring="{0:c}"
itemstyle-horizontalalign="right" />
</columns>
</asp:datagrid>
</p>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>