Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Can Some one tell me how to populate the value from a session to the controls in a page.I have the values stored in a database..I created a connection to db and the filled the values in the session..Now I wanna populate the value to the control..I have done this peice of code..but this doesnt seems to be working
//connect to database for UserSetting stable
    SqlConncetion conn = new SqlConncetion(@"Server=localhost;      Database=LCLDatabase_DEV; Integrated Security=True);

//Create DataAdapter Object
SqlDataAdapter  adapter = new SqlDataAdapter  ("Select id,valueFrom user where UserName="Samantha",conn);

//Create a Dataset 
DataSet ds=new DataSet();

//Fill dataset using the query defined for DataAdapter

adapter.Fill(this.ds,"user );

foreach(DataRow row in ds.Tables["user "].Rows)
{
    Session["id"]=value;

}

Above I have stored the value in a session from db now I wanna populate it back to control when the user samantha logsin
   foreach(controls ctrl in page. controls)
{
    if(Session[ctrl.ID]!=null)
    ctrl.value= Session[ctrl.ID].value

}


can someone tell me how to proceed further??
Posted
Updated 22-Feb-13 10:08am
v3
Comments
Richard C Bishop 22-Feb-13 16:09pm    
You are not calling the correct session variable when you are tring to take it back out. You set Session["id"] and that is what you have to use when taking your value back out of session.

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