日期:2014-05-20 浏览次数:20422 次
BLL层 /// <summary> /// 获取数据列表 /// </summary> /// <param name="dt"></param> /// <returns></returns> public List<MODEL.AA> DataTableToList(DataTable dt) { List<MODEL.AA> modellist = new List<MODEL.AA>(); int rowscount = dt.Rows.Count; if (rowscount > 0) { MODEL.AA model; for (int n = 0; n < rowscount;n++ ) { model = new MODEL.AA(); if (dt.Rows[n]["id"].ToString() != null) { model.id= int.Parse(dt.Rows[n]["id"].ToString()); } model.name= dt.Rows[n]["name"].ToString(); model.Model = dt.Rows[n]["Model"].ToString(); modellist.Add(model); } } return modellist; } 页面: private BLL.BB btp = new BLL.BB(); private MODEL.AA mtp = new MODEL.AA(); protected void Page_Load(object sender, EventArgs e) { DataTable dt = btp.GetFull(10).Tables[0];//获取数据 foreach (MODEL.AA ss in btp.DataTableToList(dt)) { string id = ss.id.ToString(); string name= ss.name.ToString(); string model = ss.Model.ToString(); Label1.Text = id; Label2.Text = name; Label3.Text = model; }