Following will use the GridView as data source (instead of a DataSet) and display the report
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.
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:
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
Edited by snufse - 03 Oct 2008 at 12:35pm