Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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...
Posted
Comments
Legor 30-Aug-12 5:39am    
This is highly related to your other question:
http://www.codeproject.com/Questions/449317/Storing-multiple-Session-Variables-in-a-single-loo

Pleaser rather improve that one instead of writing new questions.

1 solution

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

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


Best Regards
M.Mitwalli
 
Share this answer
 
Comments
ridoy 30-Aug-12 6:44am    
good..+5
Mohamed Mitwalli 30-Aug-12 6:46am    
Thanks ridoy :)
__TR__ 31-Aug-12 15:17pm    
5ed!
Mohamed Mitwalli 31-Aug-12 15:58pm    
Thanks TR :)

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