Click here to Skip to main content
15,888,301 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
protected void grdStudent_SelectedIndexChanged(object sender, EventArgs e)
{
//GridViewRow row = new GridViewRow();

Session.Add("last_name", grdStudent.SelectedRow.Cells[1].Text);
Session.Add("other_names", grdStudent.SelectedRow.Cells[2].Text);
Session.Add("marital_status", grdStudent.SelectedRow.Cells[3].Text);

if (IsPostBack)
{
txtLastname.Text = Session["last_name"].ToString();
txtOthernames.Text = Session["other_names"].ToString();
ddlMaritalStatus.SelectedValue = Session["marital_status"].ToString();

}
}


Please clarify the role of Session.Add("last_name", grdStudent.SelectedRow.Cells[1].Text);

versus Session["last_name"].ToString();


Thanks
Posted

The first is adding a Session variable and then second is using that value. Again, this is something you could easily figure out on your own if you ran the code or if you searched MSDN a little.
 
Share this answer
 
Session.Add: is used to add something to your session object. instead of using Session.Add, you can also use Session["variable"]="something"; to add value in session object. both are almost same.

Session[""].ToString();: is used to retrieve session value which is already added to session object.
 
Share this answer
 
Session["uname"]=TextBox1.Text ; It uses an indexer to assign the data. The indexer refers to the particular row of the session object. The key "uname" is
used to identify the row.

Assigning data using an indexer is faster and more efficient than assigning the data
using the method--Session.Add("uname",TextBox1.Text)

Reference :

What is the difference between Session["uname"]=TextBox1.Text and
Session.Add("uname",TextBox1.Text)?
[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900