Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0
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 21-Feb-13 19:19pm
Edited 22-Feb-13 11:08am
v3
Comments
richcb at 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)

  Print Answers RSS
0 OriginalGriff 6,803
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,421
3 Manas Bhardwaj 4,841
4 Maciej Los 4,330


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 22 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100