解释功能'Session.Add'vrs'Session'之间的区别 [英] Explain The difference between the functionality 'Session.Add' vrs 'Session'

查看:122
本文介绍了解释功能'Session.Add'vrs'Session'之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



}

}





请澄清 Session.Add(last_name,grdStudent。 SelectedRow.Cells [1] .Text);



Session [last_name]。ToString(); < br $> b $ b



谢谢

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

推荐答案

首先是添加一个Session变量然后第二是使用该值。再一次,如果您运行代码或者稍微搜索MSDN,这可以很容易地自行解决。
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.


Session.Add:用于向会话对象添加内容。而不是使用Session.Add,你也可以使用Session [variable] =something;在会话对象中添加值。两者几乎相同。



Session [] .ToString();:用于检索已添加到会话对象的会话值。
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.


查看已解决的问题什么是Session.Add(key,value)和Session [key] = value?之间的区别[ ^ ]



Session [uname] = TextBox1有什么区别.Text和Session.Add(uname,TextBox1.Text)? [ ^ ]
see solved question What's the Difference between Session.Add("key",value) and Session["key"] = value?[^]

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


这篇关于解释功能'Session.Add'vrs'Session'之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆