【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._2015_5_29.UserInfoList" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/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._2015_5_29.UserInfoList" %>
<!DOCTYPE html>
<%@ Import Namespace="CZBK.ItcastProject.Model" %>
<html xmlns="http://www.w3.org/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>

 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值