Using Templated Columns with GridView
<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Using Templated Columns with GridView</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="productsSource" runat="server"
ProviderName="System.Data.SqlClient"
ConnectionString="<%$ ConnectionStrings:AdventureWorks %>"
SelectCommand="Select ProductID, Name, ProductNumber, DaysToManufacture, SellStartDate, ReorderPoint from Production.Product">
</asp:SqlDataSource>
<asp:GridView ID="gridProducts" runat="server" DataSourceID="productsSource"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Products">
<ItemTemplate>
<%# Eval("ProductID") %> -
<%# Eval("Name") %>
Product Number: <%# Eval("ProductNumber") %><br />
Days to manufacture:<%# Eval("DaysToManufacture") %> <br />
Start Date: <%# Eval("SellStartDate", "{0:MM/dd/yy}") %><br />
Reorder Point:<%# Eval("ReorderPoint") %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
Related examples in the same category