Arun Banik
Панель, которая показывает отчет.
<asp:Panel ID="panReport" runat="server" CssClass="panelReport" Visible="false">
<table style="border-collapse:collapse; width:400px;" cellspacing="0" cellpadding="0" border="0">
<tr>
<td class="printtd"><asp:Button id="btPrintRep" CssClass="btprint" ToolTip="Print Report" Text="Print" runat="server" /></td>
<td class="printtd" style="width:20px;"><asp:Button ID="btFirstPage" ToolTip="First Page" Text="<<" CssClass="btprint" runat="server" /></td>
<td class="printtd" style="width:20px;"><asp:Button ID="btNextPage" ToolTip="Next Page" Text=">" CssClass="btprint" runat="server" /></td>
<td class="printtd" style="width:20px;"><asp:Button ID="btPrevPage" ToolTip="Previous Page" Text="<" CssClass="btprint" runat="server" /></td>
<td class="printtd" style="width:20px;"><asp:Button ID="btLastPage" ToolTip="Last Page" Text=">>" CssClass="btprint" runat="server" /></td>
<td class="printtd"><asp:Button ID="btCloseRep" ToolTip="Close" Text="Close" CssClass="btprint" runat="server" /></td>
</tr>
</table>
</asp:Panel>
С фоновым кодом
Запишите это в модуль
Public Report As CrystalDecisions.CrystalReports.Engine.ReportDocument = New CrystalDecisions.CrystalReports.Engine.ReportDocument
Public CrystalReportViewer As CrystalDecisions.Web.CrystalReportViewer = New CrystalDecisions.Web.CrystalReportViewer
Protected Sub btCloseRep_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btCloseRep.Click
panReport.Visible = False
End Sub
Protected Sub btPrintRep_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btPrintRep.Click
' PRINT.
If IsPostBack Then
Report.PrintToPrinter(1, True, 0, 0)
panReport.Visible = False
End If
End Sub
Protected Sub btFirstPage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btFirstPage.Click
ShowReport(AnySqlQuery, "Report.rpt", "Report.xsd", "MyReport", panReport, SomeParameter)
CrystalReportViewer.ShowFirstPage()
End Sub
Protected Sub btNextPage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btNextPage.Click
ShowReport(AnySqlQuery, "Report.rpt", "Report.xsd", "MyReport", panReport, SomeParameter)
CrystalReportViewer.ShowNextPage()
End Sub
Protected Sub btPrevPage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btPrevPage.Click
ShowReport(AnySqlQuery, "Report.rpt", "Report.xsd", "MyReport", panReport, SomeParameter)
CrystalReportViewer.ShowPreviousPage()
End Sub
Protected Sub btLastPage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btLastPage.Click
ShowReport(AnySqlQuery, "Report.rpt", "Report.xsd", "MyReport", panReport, SomeParameter)
CrystalReportViewer.ShowLastPage()
End Sub
- ПОКАЗАТЬ ОТЧЕТ.
Private Function ShowReport(ByVal sQuery As String, ByVal rptFileName As String, ByVal xsdFileName As String, ByVal sTableName As String, _
ByRef panReport As Panel, ByVal sParameter As String) As Boolean
Try
If Trim(gS_UserFullName) <> "" Then
Dim objDataAdapter As New System.Data.SqlClient.SqlDataAdapter(sQuery, myConn)
Dim objDataSet As New DataSet
objDataAdapter.SelectCommand.CommandTimeout = 500
objDataAdapter.Fill(objDataSet, sTableName)
' CREATE THE XML FILE IN THE BASE DIRECTORY AND LOAD THE REPORT.
objDataSet.WriteXmlSchema(System.AppDomain.CurrentDomain.BaseDirectory() & "reports\" & xsdFileName)
Report.Load(System.AppDomain.CurrentDomain.BaseDirectory() & "reports\" & rptFileName & "")
Report.SetDataSource(objDataSet) ' SET REPORT DATA SOURCE.
' PASS PARAMETERS.
Report.Refresh()
Report.SetParameterValue("RepHeader", sReportHeader)
CrystalReportViewer.BorderStyle = BorderStyle.None
CrystalReportViewer.DisplayGroupTree = False : CrystalReportViewer.DisplayToolbar = False
CrystalReportViewer.Zoom(150)
CrystalReportViewer.BestFitPage = False : CrystalReportViewer.HasCrystalLogo = False
CrystalReportViewer.Width = "1180" : CrystalReportViewer.Height = "770"
CrystalReportViewer.ReportSource = Report
panReport.Controls.Add(CrystalReportViewer) ' ADD THE VIEWER WITH A PANEL CONTROL ON THE PAGE.
panReport.Visible = True
ShowReport = True
End If
Catch ex As Exception
ShowReport = False
Finally
End Try
End Function