使用会话变量 [英] Working with Session Variables

查看:64
本文介绍了使用会话变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,有人可以帮我如何通过循环来在会话中存储10个texboxes值,以及如何在提交"按钮中调用它.


我的页面已集成到母版页中.



谢谢...

Hi can any one help me how to store 10 texboxes values in sessions by taking a loop, and also how to call it in the submit button.


My page is integrated to the master page.



Thanks...

推荐答案


检查此
请注意,循环会根据包含控件的容器而改变

Hi ,
Check this
Be aware of the loop will change according to container which contain the controls

List<string> txt = new List<string>();
protected void Button1_Click(object sender, EventArgs e)
{
    foreach (Control ctrl in form1.Controls)
    {
        if (ctrl is TextBox)
        {
            txt.Add(((TextBox)ctrl).Text);
            Session.Add("lst",txt);
        }
    }
}
protected void Button2_Click(object sender, EventArgs e)
{
  txt=(List<string>)  Session["lst"];
    GridView1.DataSource = txt.ToList();
    GridView1.DataBind();
}



最好的问候
米特瓦里(M.Mitwalli)



Best Regards
M.Mitwalli


这篇关于使用会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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