700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 【ASP.NET】——aspx与aspx.cs两种调用方法

【ASP.NET】——aspx与aspx.cs两种调用方法

时间:2019-01-21 11:56:04

相关推荐

【ASP.NET】——aspx与aspx.cs两种调用方法

【第一种】

在.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>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。