【第一种】
在.aspx.cs中写
public partial class UserInfoList : System.Web.UI.Page{public string StrHtml { get; set; }protected void Page_Load(object sender, EventArgs e){BLL.UserInfoService UserInfoService = new BLL.UserInfoService();List<UserInfo>list=UserInfoService.GetList();StringBuilder sb = new StringBuilder();foreach (UserInfo userInfo in list){sb.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td></tr>",userInfo.Id,userInfo.UserName,userInfo.UserPass,userInfo.Email,userInfo.RegTime.ToShortDateString());}StrHtml = sb.ToString();}}
在.aspx中写
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UserInfoList.aspx.cs" Inherits="CZBK.ItcastProject.WebApp.__5_29.UserInfoList" %><!DOCTYPE html><html xmlns="/1999/xhtml"><head runat="server"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title></title><script type="text/javascript">window.onload = function () {};</script></head><body><form id="form1" runat="server"><div><table> <tr><th>编号</th><th>用户名</th><th>密码</th><th>邮箱</th><th>时间</th><th>删除</th><th>详细</th><th>编辑</th></tr><%=StrHtml%></table></div></form></body></html>
【第二种】
public partial class UserInfoList : System.Web.UI.Page{public string StrHtml { get; set; }public List<UserInfo> UserList { get; set; }protected void Page_Load(object sender, EventArgs e){BLL.UserInfoService UserInfoService = new BLL.UserInfoService();List<UserInfo>list=UserInfoService.GetList();UserList = list;}}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UserInfoList.aspx.cs" Inherits="CZBK.ItcastProject.WebApp.__5_29.UserInfoList" %><!DOCTYPE html><%@ Import Namespace="CZBK.ItcastProject.Model" %><html xmlns="/1999/xhtml"><head runat="server"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title></title><script type="text/javascript">window.onload = function () { };</script></head><body><form id="form1" runat="server"><div><table> <tr><th>编号</th><th>用户名</th><th>密码</th><th>邮箱</th><th>时间</th><th>删除</th><th>详细</th><th>编辑</th></tr><% foreach(UserInfo userInfo in UserList){%><tr><td><%=userInfo.Id %></td><td><%=userInfo.UserName %></td><td><%=userInfo.UserPass %></td><td><%=userInfo.Email %></td><td><%=userInfo.RegTime.ToShortDateString() %></td></tr><%} %></table></div></form></body></html>