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; } }}
调用SqlHelper将这个查询出来的数据转换成一个 list对象(将查询出来的数据映射到实体类上)
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Data;namespace 实体类.ModelService{ public class UserService { public static List SelectDataToEntity() { //通过查询数据库,将获取到的数据转换成一个list List list = SqlHelper.SelectDataToList ("select * from T_User"); return list; } }}
WebForm1.aspx.cs页面 (注意:WebForm1.aspx页面是继承WebForm1.aspx.cs类的)
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 lsit)存放到 Session里。然后可以在WebForm1.aspx页面中来遍历这个list 从而取到实体类的数据 Session.Add("User", UserService.SelectDataToEntity()); } }}
WebForm1.aspx页面
查看更多关于WebForm获取实体类的数据,填充页面(用session传值)_html/css_WEB-ITno的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did106842