Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > Crystal Reports
|
Crystal Reports General discussion about Crystal Reports. For discussions specific to the book Professional Crystal Reports for VS.NET, please see the book discussion forum for that book.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Crystal Reports section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 3rd, 2008, 12:47 PM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 205
Thanks: 4
Thanked 0 Times in 0 Posts
Default [Resolved] CR and SetDataSource

I have as ASP application where I use a DataSet to display a GridView with a click button to display the report. It works fine

Dim mySqlDataSet As New Data.DataSet
mySqlDataSet = Session("MySqlDataSet")
myCrystalReport.Load(Server.MapPath("CrystalReport 1.rpt"))
myCrystalReport.SetDataSource(mySqlDataSet)
CrystalReportViewer1.ReportSource = myCrystalReport

On the user interface I allow user to sort columns in the GridView. This bring me to my question: I would like to show the report the way the GridView is sorted. This means that I would like to use the GridView as data source for the report. What options do I have? Thank you.
 
Old October 6th, 2008, 07:33 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 205
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Think I figured it out and it works.

Following will use the GridView as data source (instead of a DataSet) and display the report

Code:
Dim GridView1 As New GridView
GridView1.DataSource = Session("myGridView")
myCrystalReport.Load(Server.MapPath("CrystalReport1.rpt"))
myCrystalReport.SetDataSource(GridView1.DataSource)
CrystalReportViewer1.ReportSource = myCrystalReport
Now:

The initial display of the DataGrid. Save the GridView.DataSource in a Session variable. This will save the sort order to be used in CR.

Code:
Public Sub DisplayGridView()
Try
 GridView1.DataSource = mySqlDataSet.Tables("JobListTable")
 GridView1.DataBind()
 Session("myGridView") = GridView1.DataSource
 initialSort = False
Catch ex As Exception
 ErrorString = ex.ToString
 ASPNET_MsgBox("An error has occurred displaying the data: " + vbCrLf + ErrorString)
 End Try
 End Sub

When sorting grid column(s) and you want CR to display the same sort order:

Code:
Protected Sub gridView1_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs)
 GridViewSortExpression = e.SortExpression
 GridView1.DataSource = mySqlDataSet.Tables("JobListTable")
 Dim pageIndex As Integer = GridView1.PageIndex
 GridView1.DataSource = SortDataTable(GridView1.DataSource, False)
 GridView1.DataBind()
 GridView1.PageIndex = pageIndex
 Session("myGridView") = GridView1.DataSource
End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
"The remote name could not be resolved" teddyk ASP.NET 2.0 Basics 0 October 28th, 2008 12:49 AM
Passing Parameters and using SetDataSource bhavesh_busa Crystal Reports 0 August 10th, 2007 10:01 AM
[Resolved] Web Service CR Refresh problem windsurfkid Crystal Reports 1 February 24th, 2007 11:29 AM
SetDataSource is ignored, the whole table is shown anjulis Crystal Reports 0 October 20th, 2006 12:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.