harry code

harry code

  • NA
  • 124
  • 22.8k

State Management

Nov 22 2018 1:00 AM
Hi,
I am having a problem in understanding the below code.
it is a task regarding performiong crud operations with out using Data base  with help of collections.
 
i am not able to understand How  session is  having the values despite not assaigning values to session.
 
 
 
Thank you in advance 
 
class Employee
{
public int eid { get; set; }
public string name { get; set; }
public decimal salary { get; set; }
}
 
public partial class WebForm1 : System.Web.UI.Page
{
Employee obj = new Employee();
List<Employee> el = new List<Employee>();
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
Session["emp"] = el;
}
el=(List<Employee>)Session["emp"];
}
protected void Button1_Click(object sender, EventArgs e)
{
obj.eid = int.Parse(TextBox1.Text);
obj.name = TextBox2.Text;
obj.salary = Convert.ToDecimal(TextBox3.Text);
el = (List<Employee>)Session["emp"];
el.Add(obj);
GridView1.DataSource = el.ToList();
GridView1.DataBind();
}
}

Answers (8)