ListViewAlternatingItemTemplate.aspx
<%@ Page Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>ListView ItemTemplate and AlternatingItemTemplate - how to use</title>
<style type="text/css">
.TableCSS
{
border-style:none;
background-color:IndianRed;
width: 700px;
}
.TableHeader
{
background-color:Crimson;
color:Snow;
font-size:large;
font-family:Verdana;
height:45px;
text-align:center;
}
.ItemCSS
{
background-color:IndianRed;
color:Snow;
font-family:MS Sans Serif;
font-size:medium;
font-weight:bold;
height:28px;
}
.AlternatingItemCSS
{
background-color:Salmon;
color:Snow;
font-family:MS Sans Serif;
font-size:medium;
font-weight:bold;
height:28px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:OliveDrab; font-style:italic;">
ListView Example: How To Use <br /> ItemTemplate And AlternatingItemTemplate
</h2>
<hr width="575" align="left" color="Salmon" />
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="Select Top 10 ProductName, UnitPrice, QuantityPerUnit From products Order By ProductName"
>
</asp:SqlDataSource>
<br />
<asp:ListView
ID="ListView1"
runat="server"
DataSourceID="SqlDataSource1"
>
<LayoutTemplate>
<table runat="server" class="TableCSS">
<tr runat="server" class="TableHeader">
<td runat="server">Product Name</td>
<td runat="server">Unit Price</td>
<td runat="server">Quantity Per Unit</td>
</tr>
<tr id="ItemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr class="ItemCSS">
<td>
<asp:Label
ID="Label1"
runat="server"
Text='<%# Eval("ProductName")%>'
>
</asp:Label>
</td>
<td>
<asp:Label
ID="Label2"
runat="server"
Text='<%# Eval("UnitPrice")%>'
>
</asp:Label>
</td>
<td>
<asp:Label
ID="Label3"
runat="server"
Text='<%# Eval("QuantityPerUnit")%>'
>
</asp:Label>
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr class="AlternatingItemCSS">
<td>
<asp:Label
ID="Label1"
runat="server"
Text='<%# Eval("ProductName")%>'
>
</asp:Label>
</td>
<td>
<asp:Label
ID="Label2"
runat="server"
Text='<%# Eval("UnitPrice")%>'
>
</asp:Label>
</td>
<td>
<asp:Label
ID="Label3"
runat="server"
Text='<%# Eval("QuantityPerUnit")%>'
>
</asp:Label>
</td>
</tr>
</AlternatingItemTemplate>
</asp:ListView>
</div>
</form>
</body>
</html>
No comments:
Post a Comment