473,657 Members | 2,430 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do i export crystal report in asp.net using the export button?

1 New Member
Hi All,

I have a crystal report that loads default values from the database, using SQL server 2005. On my web page, I have 2 databound dropdownlist and upon selectedindexch anged the report must reload data based on selectedindex.

However only the first page of the report refreshes while the other pages remain with the initial data. When I try to export the report to excel using the export button from the crystalreportvi ewer toolbar it re-load the initial report.

Here is my code:
Expand|Select|Wrap|Line Numbers
  1.  
  2. Imports System
  3. Imports System.Web
  4. Imports System.Web.UI
  5. Imports System.Web.UI.WebControls
  6. Imports System.Data
  7. Imports System.Data.SqlClient
  8. Imports System.Configuration
  9. Imports CrystalDecisions.CrystalReports.Engine
  10. Imports CrystalDecisions.Shared
  11. Imports CrystalDecisions.CrystalReports.Engine.ReportDocument
  12.  
  13. Partial Class RptTraining
  14.     Inherits System.Web.UI.Page
  15.     Dim oRpt As New ReportDocument()
  16.     Dim sqlConn As New SqlConnection
  17.     Dim strConnection As String
  18.     Dim MyCommand As New SqlClient.SqlCommand()
  19.     Dim MyDA As New SqlClient.SqlDataAdapter()
  20.     Dim myDS As New DataSet3()
  21.     Dim x As Integer
  22.     Dim AppID As Integer
  23.     Dim yr As String
  24.     Dim c As String
  25.     Dim comp As String
  26.     Dim ParaFields As New ParameterFields()
  27.     Dim p1 As New ParameterField()
  28.     Dim pd1 As New ParameterDiscreteValue()
  29.  
  30.     Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
  31.  
  32.         BindReport()
  33.  
  34.     End Sub
  35.  
  36.     Sub BindReport()
  37.  
  38.         x = ddlTraining.SelectedIndex
  39.         If x = 1 Then
  40.             AppID = 15
  41.         ElseIf x = 2 Then
  42.             AppID = 16
  43.         ElseIf x = 3 Then
  44.             AppID = 17
  45.         ElseIf x = 4 Then
  46.             AppID = 18
  47.         End If
  48.  
  49.         strConnection = ConfigurationManager.ConnectionStrings("spaceConnectionString").ConnectionString
  50.         sqlConn = New SqlConnection(strConnection)
  51.         MyCommand.Connection = sqlConn
  52.         MyCommand.CommandText = "SELECT  dbo.HR_company.CmpName AS CompanyName, dbo.HR_Master.SurName, dbo.HR_Master.ForeName,dbo.HR_Master.EmpType AS HMGrade, dbo.HR_depart.DptName AS Department, dbo.HR_post.PostName AS Post,dbo.HR_Training_Needs.TrainCourse AS Course, dbo.HR_Training_Needs.TrainSupplier AS CourseProvider,dbo.HR_Training_Needs.TrainPriority AS Priority FROM dbo.HR_company INNER JOIN dbo.HR_Master ON dbo.HR_company.Company = dbo.HR_Master.Company AND dbo.HR_company.InstalCode = dbo.HR_Master.InstalCode INNER JOIN dbo.HR_depart ON dbo.HR_Master.DptCode = dbo.HR_depart.Dptcode AND dbo.HR_Master.Company = dbo.HR_depart.Company AND dbo.HR_Master.InstalCode = dbo.HR_depart.InstalCode INNER JOIN dbo.HR_post ON dbo.HR_Master.PostCode = dbo.HR_post.PostCode AND dbo.HR_Master.Company = dbo.HR_post.Company AND dbo.HR_Master.InstalCode = dbo.HR_post.InstalCode INNER JOIN dbo.HR_Training_Needs ON dbo.HR_Master.AcSIPFNo = dbo.HR_Training_Needs.WinLogin WHERE(dbo.HR_Training_Needs.AppraisalID = 16)ORDER BY dbo.HR_Master.SurName, dbo.HR_Master.ForeName, Department"
  53.         MyDA.SelectCommand = MyCommand  
  54.         MyDA.Fill(myDS, "training")
  55.         oRpt.Load("C:\Inetpub\wwwroot\HR\reports\TrainingNeeds.rpt")
  56.         oRpt.SetDataSource(myDS)
  57.         CrystalReportViewer1.ReportSource = oRpt
  58.  
  59.  
  60.         p1 = New ParameterField()
  61.         pd1 = New ParameterDiscreteValue()
  62.         p1.ParameterFieldName = "year"
  63.         pd1.Value = "2008"
  64.         p1.CurrentValues.Add(pd1)
  65.         ParaFields.Add(p1)
  66.         CrystalReportViewer1.ParameterFieldInfo = ParaFields
  67.  
  68.  
  69.  
  70.     End Sub
  71.  
  72.     Protected Sub ddlTraining_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlTraining.SelectedIndexChanged
  73.  
  74.         ConfigureReport()
  75.  
  76.     End Sub
  77.  
  78.     Sub ConfigureReport()
  79.  
  80.         x = ddlTraining.SelectedIndex
  81.         If x = 1 Then
  82.             AppID = 15
  83.         ElseIf x = 2 Then
  84.             AppID = 16
  85.         ElseIf x = 3 Then
  86.             AppID = 17
  87.         ElseIf x = 4 Then
  88.             AppID = 18
  89.         End If
  90.  
  91.         strConnection = ConfigurationManager.ConnectionStrings("spaceConnectionString").ConnectionString
  92.         sqlConn = New SqlConnection(strConnection)
  93.         MyCommand.Connection = sqlConn
  94.         MyCommand.CommandText = "SELECT  dbo.HR_company.CmpName AS CompanyName, dbo.HR_Master.SurName, dbo.HR_Master.ForeName,dbo.HR_Master.EmpType AS HMGrade, dbo.HR_depart.DptName AS Department, dbo.HR_post.PostName AS Post,dbo.HR_Training_Needs.TrainCourse AS Course, dbo.HR_Training_Needs.TrainSupplier AS CourseProvider,dbo.HR_Training_Needs.TrainPriority AS Priority FROM dbo.HR_company INNER JOIN dbo.HR_Master ON dbo.HR_company.Company = dbo.HR_Master.Company AND dbo.HR_company.InstalCode = dbo.HR_Master.InstalCode INNER JOIN dbo.HR_depart ON dbo.HR_Master.DptCode = dbo.HR_depart.Dptcode AND dbo.HR_Master.Company = dbo.HR_depart.Company AND dbo.HR_Master.InstalCode = dbo.HR_depart.InstalCode INNER JOIN dbo.HR_post ON dbo.HR_Master.PostCode = dbo.HR_post.PostCode AND dbo.HR_Master.Company = dbo.HR_post.Company AND dbo.HR_Master.InstalCode = dbo.HR_post.InstalCode INNER JOIN dbo.HR_Training_Needs ON dbo.HR_Master.AcSIPFNo = dbo.HR_Training_Needs.WinLogin WHERE(dbo.HR_Training_Needs.AppraisalID = '" & AppID & "')ORDER BY dbo.HR_Master.SurName, dbo.HR_Master.ForeName, Department"
  95.         MyDA.SelectCommand = MyCommand
  96.         myDS.Clear()
  97.         MyDA.Fill(myDS, "training")
  98.         oRpt.Load("C:\Inetpub\wwwroot\HR\reports\TrainingNeeds.rpt")
  99.         oRpt.SetDataSource(myDS)
  100.         CrystalReportViewer1.ReportSource = oRpt
  101.  
  102.  
  103.         p1 = New ParameterField()
  104.         pd1 = New ParameterDiscreteValue()
  105.         p1.ParameterFieldName = "year"
  106.         If x = 1 Then
  107.             pd1.Value = "2008"
  108.         ElseIf x = 2 Then
  109.             pd1.Value = "2009"
  110.         ElseIf x = 3 Then
  111.             pd1.Value = "2010"
  112.         ElseIf x = 4 Then
  113.             pd1.Value = "2011"
  114.         End If
  115.         p1.CurrentValues.Add(pd1)
  116.         ParaFields.Add(p1)
  117.         CrystalReportViewer1.ParameterFieldInfo = ParaFields
  118.  
  119.  
  120.     End Sub
  121.     Sub RefreshReport()
  122.  
  123.         x = ddlTraining.SelectedIndex
  124.         If x = 1 Then
  125.             AppID = 15
  126.             yr = 2008
  127.         ElseIf x = 2 Then
  128.             AppID = 16
  129.             yr = 2009
  130.         ElseIf x = 3 Then
  131.             AppID = 17
  132.             yr = 2010
  133.         ElseIf x = 4 Then
  134.             AppID = 18
  135.             yr = 2011
  136.         End If
  137.  
  138.         c = ddlsbu.SelectedIndex
  139.         If c = 1 Then
  140.             comp = "ACTIVELINE LTD"
  141.         ElseIf c = 2 Then
  142.             comp = "HAREL MALLAC CO LTD (MAN.)"
  143.         ElseIf c = 3 Then
  144.             comp = "HM ENGINEERING LTD (MAN)"
  145.         ElseIf c = 4 Then
  146.             comp = "HM BUREAUTIQUE (MAN)"
  147.         ElseIf c = 5 Then
  148.             comp = "HAREL MALLAC CO LTD"
  149.         ElseIf c = 6 Then
  150.             comp = "HAREL MALLAC TRAVEL & LEISURE"
  151.         ElseIf c = 7 Then
  152.             comp = "HAREL MALLAC AVIATION LTD"
  153.         ElseIf c = 8 Then
  154.             comp = "HM ENGINEERING LTD."
  155.         ElseIf c = 9 Then
  156.             comp = "HM BUREAUTIQUE LTD."
  157.         ElseIf c = 10 Then
  158.             comp = "MCS EXECUTIVES"
  159.         ElseIf c = 11 Then
  160.             comp = "MAURITIUS COMPUTING SERVICES"
  161.         ElseIf c = 12 Then
  162.             comp = "HM TECHNOLOGIES (MANAGEMENT)"
  163.         ElseIf c = 13 Then
  164.             comp = "HM TECHNOLOGIES"
  165.         End If
  166.         strConnection = ConfigurationManager.ConnectionStrings("spaceConnectionString").ConnectionString
  167.         sqlConn = New SqlConnection(strConnection)
  168.         MyCommand.Connection = sqlConn
  169.         MyCommand.CommandText = "SELECT  dbo.HR_company.CmpName AS CompanyName, dbo.HR_Master.SurName, dbo.HR_Master.ForeName,dbo.HR_Master.EmpType AS HMGrade, dbo.HR_depart.DptName AS Department, dbo.HR_post.PostName AS Post,dbo.HR_Training_Needs.TrainCourse AS Course, dbo.HR_Training_Needs.TrainSupplier AS CourseProvider,dbo.HR_Training_Needs.TrainPriority AS Priority FROM dbo.HR_company INNER JOIN dbo.HR_Master ON dbo.HR_company.Company = dbo.HR_Master.Company AND dbo.HR_company.InstalCode = dbo.HR_Master.InstalCode INNER JOIN dbo.HR_depart ON dbo.HR_Master.DptCode = dbo.HR_depart.Dptcode AND dbo.HR_Master.Company = dbo.HR_depart.Company AND dbo.HR_Master.InstalCode = dbo.HR_depart.InstalCode INNER JOIN dbo.HR_post ON dbo.HR_Master.PostCode = dbo.HR_post.PostCode AND dbo.HR_Master.Company = dbo.HR_post.Company AND dbo.HR_Master.InstalCode = dbo.HR_post.InstalCode INNER JOIN dbo.HR_Training_Needs ON dbo.HR_Master.AcSIPFNo = dbo.HR_Training_Needs.WinLogin WHERE(dbo.HR_Training_Needs.AppraisalID = '" & AppID & "' and HR_company.CmpName = '" & comp & "')ORDER BY HR_company.CmpName, HR_Master.SurName, HR_Master.ForeName, Department"
  170.         MyDA.SelectCommand = MyCommand
  171.         myDS.Tables("finalrating").Clear()
  172.         MyDA.Fill(myDS, "finalrating")
  173.         oRpt.Load("C:\Inetpub\wwwroot\HR\reports\FinalRating.rpt")
  174.         oRpt.SetDataSource(myDS)
  175.         CrystalReportViewer1.ReportSource = oRpt
  176.  
  177.  
  178.         p1 = New ParameterField()
  179.         pd1 = New ParameterDiscreteValue()
  180.         p1.ParameterFieldName = "year"
  181.         If x = 1 Then
  182.             pd1.Value = "2008"
  183.         ElseIf x = 2 Then
  184.             pd1.Value = "2009"
  185.         ElseIf x = 3 Then
  186.             pd1.Value = "2010"
  187.         ElseIf x = 4 Then
  188.             pd1.Value = "2011"
  189.         End If
  190.         p1.CurrentValues.Add(pd1)
  191.         ParaFields.Add(p1)
  192.         CrystalReportViewer1.ParameterFieldInfo = ParaFields
  193.  
  194.  
  195.     End Sub
  196.     Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
  197.  
  198.         oRpt.Close()
  199.         oRpt.Dispose()
  200.     End Sub
  201.  
  202.     Protected Sub ddlsbu_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlsbu.SelectedIndexChanged
  203.  
  204.         RefreshReport()
  205.  
  206.     End Sub
  207.  
  208. End Class
  209.  
  210.  
How do I refresh the whole report on selectedindexch ange?

How do I export the current report to excel?

Thanking you in advance for your help
Oct 26 '10 #1
0 2316

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1322
by: Peter | last post by:
How to populate text hello into a Crystal Report using C#. Any help. Thanks.
0
2678
by: RAF | last post by:
hi i want to export crystal report to html format i am using following code Dim rpt As New test Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here CrystalReportViewer1.ReportSource = rpt End Sub
3
3669
by: Colin Graham | last post by:
Error when attempting to export Crystal Report as PDF document asp.net. I get the following error. Error in File C:\DOCUME~1\W2K-AD~1\ASPNET\LOCALS~1\Temp\temp_512d88ae-f721-4860-a57f-2eae219dc1c4.rpt: Invalid export DLL or export format. I have recently created an asp.net deployment application. When i ran the deployment on the server i have had numerous issues but manged to
0
1384
by: Pierre | last post by:
Hi, Can anyone tell me how I can populate a Crystal Report, using a DataTable in C#? Regards, Pierre
1
2422
by: Paul | last post by:
Not sure if I am posting this to the correct group but I have a .NET web application and have a datagrid that is filled with a dataset. The data comes from a stored procedure that returns several records from a database that is called from the web application. I want the application to create a crystal report using the data source that is used for the data grid, from the same dataset, or the output of the stored procedure. Just wondering...
0
1027
by: Simon Abolnar | last post by:
Is it possible to export Crystal Report to PDF using memory. I would like that report is opened in PDF reader after user click a button. This is very simple to do in ASP.NET, but I would like to do this with Windows application. Could you help me with an example of code. Thanks for help!
5
25027
by: Badis | last post by:
Hi, Could any one give a sample example on how to export crystal report called "MyReport.rpt" to PDF using Crystal Report !!? Thanks
2
6467
by: Hellotalktome13 | last post by:
Using a simple ASP.net page with a crystal report on it. Loading from IIS using Integrated Secruity in the reports connection string it populates the report in the browser. What User ID and password is Crystal Report using to get permission to access the database? I created a simple ASP.net page with a data grid using integrated security. It gives an error that it's not a trusted user.
0
1871
by: amiga500 | last post by:
Hello, I am developing a crystal report called Expense Report (I am not an expert Crystal Report designer) if someone could help me in this problem I would be greatly appreciate it. The report would be as follows: Description Sun Mon
0
1643
by: SLauren | last post by:
Hi, I am new to crystal report. Can anyone please suggest how can i generate a crystal report using dataset without a report object? I have a crystal report (.rpt) with a mapped dataset. How can i populate data within it without a report object? Thanks in advance.... Regards, Lauren
0
8823
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8726
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8603
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7320
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1944
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1604
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.