Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maintain DataTable & Variables throughout Session

I have created the website in which i have to maintain the datatables & some variables in memory. Data/values in datatable or varibales will be different as per the logged user. how to maintain it?

like image 208
Rohit Chaudhari Avatar asked Jan 28 '26 10:01

Rohit Chaudhari


1 Answers

You can save them as

DataTable dt = new DataTable();
// I assumed that dt has some data

Session["dataTable"] = dt; // Saving datatable to Session
// Retrieving 
DataTable dtt = (DataTable) Session["dataTable"]; // Cast it to DataTable

int a = 43432;
Session["a"] = a;
// Retrieving 
int aa = (int) Session["a"];

// classes
  class MyClass
  {
    public int a { get; set; }
    public int b { get; set; }
  }

  protected void Page_Load(object sender, EventArgs e)
  {

    MyClass obj = new MyClass();
    obj.a = 5;
    obj.b = 20;

    Session["myclass"] = obj;  // Save the class object in Session
     // Retrieving 
      MyClass obj1 = new MyClass();
       obj1 = (MyClass) Session["myclass"]; // Remember casting the object
   }
like image 93
Waqar Janjua Avatar answered Jan 30 '26 23:01

Waqar Janjua