<1>
First create an entity class User
Using system;using system.collections.generic;using system.linq;using System.web;namespace entity class {public class User {public int Id {get; set;} public string UserName {get; set;} public int Age {get; set;} public int Gender {get; set;}} }
<2>
Call SqlHelper to convert the queried data into a list object (map the queried data to the entity class)
</pre><pre name= "code" class= "CSharp" >using system;using system.collections.generic;using System.Linq; The Using System.web;using System.data;namespace entity class. modelservice{public class UserService {public static list<user> selectdatatoentity () { //By querying the database to convert the obtained data into a list list<user> list = sqlhelper.selectdatatolist<user> ("SELECT * from T_user"); return list;}} }
<3>
WebForm1.aspx.cs page (Note: The WebForm1.aspx page is inherited from the WebForm1.aspx.cs class)
Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.UI;using System.web.ui.webcontrols;using entity class. Modelservice;namespace entity class {public partial class WebForm1:System.Web.UI.Page { protected void Page_Load ( Object sender, EventArgs e) { //The retrieved List (list<user> lsit) is stored in the session. You can then traverse the list in the WebForm1.aspx page to fetch the data session.add ("User", Userservice.selectdatatoentity ()) of the entity class;}}
<4>
WebForm1.aspx page
<%@ page language= "C #" autoeventwireup= "true" codebehind= "WebForm1.aspx.cs" inherits= "entity class. WebForm1 "%><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
WebForm get the data of the entity class, populate the page (pass value by session)