---
title: "How to get Crystal Report data in session"  
description: "How to get Crystal Report data in session"  
author: "Mark Devid"  
published: 2014-11-01  
updated: 2014-11-01  
canonical: https://www.mindstick.com/forum/2487/how-to-get-crystal-report-data-in-session  
category: "php"  
tags: ["crystal report", "session"]  
reading_time: 2 minutes  

---

# How to get Crystal Report data in session

I have noticed that [crystal report](https://www.mindstick.com/articles/930/crystal-report-in-visual-studio-2010) runs the [Linq query](https://www.mindstick.com/forum/33908/how-to-select-and-retrieve-data-using-linq-query-in-entity-framework) once again when the page index is changed, means when we load [second page](https://www.mindstick.com/forum/23130/windows-phone-8-1-universal-app-terminates-on-navigating-back-from-second-page) from first page? So just wanted to know if we can get which page is loaded so that we can keep [values](https://www.mindstick.com/forum/327/sum-textbox-values) in [session](https://www.mindstick.com/articles/12042/session-in-c-sharp).

Just a hint is [required](https://www.mindstick.com/forum/160269/what-is-required-data-annotation-how-does-it-affect-model-validation) as I am not getting the desired [results](https://yourviews.mindstick.com/story/4497/usage-of-baking-soda-magical-results) from Google.

**[Update](https://www.mindstick.com/forum/156353/what-is-hummingbird-update): I am sorry in a hurry I just clicked on a wrong tag.** So the [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) is like:

This is my code below which I use fr running my crystal report:

```
var rpt = new Result();
List<class> lst1 = new DALMethod().Get();
rpt.SetDataSource(lst1);
CRReportViewer.ReportSource = rpt;
```

When I switch from page one to two or more, this method in DAL is called again taking the same time it took first time to load, so I just want to have the data in session when query runs first time, and next time when I get the page index, then I will show data from session.

Is there a way around by which I can get the page index in this [c# code](https://www.mindstick.com/forum/403/how-to-export-data-in-excel-file-from-sql-server-using-c-sharp-code)?

## Replies

### Reply by Royce Roy

I had found the solution, hope this might help someone else: I was using a generic list as a data source:

1. As soon as we get to know the page loads for the first time, I mean not a postback, we can initialize a list to be maintained in session.

2. After showing the report we can add the data source (which is a list type).

3. On Report page shift data will be taken from session.

```
if (!IsPostBack){ //clear session and create new session
 Session["ReportGenericList"] = null;
}
List<class> datasourceLst=null; if (Session["ReportGenericList"] != null)  {
    datasourceLst= (List<class>)Session["ReportGenericList"];
  }
else  {   datasourceLst = //call methods to fill datasource   Session["ReportGenericList"] = datasourceLst;}
```


---

Original Source: https://www.mindstick.com/forum/2487/how-to-get-crystal-report-data-in-session

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
