.aspx代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ListView练习.aspx.cs" Inherits="ListView练习" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" ItemPlaceholderID="holder"><%--ItemPlaceholderID="holder"重要告诉Item占位符的ID--%>
<LayoutTemplate><%--1布局模板必要--%>
<p>员工信息表</p>
<p>TEST</p>
<p runat="server" id="holder"></p><%--id="holder"告诉ItemTemplate插入到哪个位置--%>
<p>TEST</p>
</LayoutTemplate>
<ItemTemplate><%--2数据模板必要--%>
<p> <%#Eval("姓名")%> <%#Eval("年龄")%></p><%--姓名和年龄是字段名--%>
</ItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:userinfoConnectionString %>"
SelectCommand="SELECT * FROM [员工信息表]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
效果如下: