WebForm get the data of the entity class, populate the page (pass value by session)

Source: Internet
Author: User

<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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.