Maison >interface Web >tutoriel HTML >WebForm 获取实体类的数据,填充页面(用session传值)_html/css_WEB-ITnose
using System;using System.Collections.Generic;using System.Linq;using System.Web;namespace 实体类{ public class User { public int Id { get; set; } public string UserName { get; set; } public int Age { get; set; } public int Gender { get; set; } }}
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Data;namespace 实体类.ModelService{ public class UserService { public static List<user> SelectDataToEntity() { //通过查询数据库,将获取到的数据转换成一个list List<user> list = SqlHelper.SelectDataToList<user>("select * from T_User"); return list; } }}</user></user></user>
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using 实体类.ModelService;namespace 实体类{ public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //将获取到的list(List<user> lsit)存放到 Session里。然后可以在WebForm1.aspx页面中来遍历这个list 从而取到实体类的数据 Session.Add("User", UserService.SelectDataToEntity()); } }}</user>
<title></title>