ASP.NET
  Home arrow ASP.NET arrow Page 6 - Programming Crystal Reports with ASP.NET 2...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Programming Crystal Reports with ASP.NET 2.0
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 145
    2007-06-04

    Table of Contents:
  • Programming Crystal Reports with ASP.NET 2.0
  • Adding a Crystal Report to the Project
  • Crystal Report Components
  • Providing Login information for the CrystalReportViewer control dynamically
  • Hiding the toolbar and adding First, Last, Next and Previous page buttons to the report
  • Enhancing the report with run-time binding along with session handling

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Programming Crystal Reports with ASP.NET 2.0 - Enhancing the report with run-time binding along with session handling


    (Page 6 of 6 )

    In all of the above sections, the CrystalReportViewer worked with CrystalReportSource. Now, let us dynamically add a report source to the CrystalReportViewer and bind it at runtime. This gives us the flexibility to use the same viewer for different reports (showing one at a time).

    Add a new web page to the project, add the four buttons (First, Previous, Next and Last) and a CrystalReportViewer control. Modify the CrystalReportViewer control, so that it looks like the following:

    <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="True" ReuseParameterValuesOnRefresh="True" DisplayToolbar="False" EnableDatabaseLogonPrompt="False" EnableParameterPrompt="False" DisplayGroupTree="False"

    Height="1064px" Width="928px" />

    In the code-behind, add the following at the top:

    Imports CrystalDecisions.Shared

    Imports CrystalDecisions.CrystalReports.Engine

    Add a new method as follows:

    Private Sub BindReport()

     

      If Session("Rep") Is Nothing Then

        Dim ConnInfo As New ConnectionInfo

        With ConnInfo

          .ServerName = ".sqlexpress"

          .DatabaseName = "Northwind"

          .UserID = "sa"

          .Password = "eXpress2005"

        End With

     

        Dim rep As New ReportDocument

        rep.Load(Server.MapPath("SampleRpt01.rpt"))

        Me.CrystalReportViewer1.ReportSource = rep

        Dim RepTbls As Tables = rep.Database.Tables

        For Each RepTbl As Table In RepTbls

          Dim RepTblLogonInfo As TableLogOnInfo = RepTbl.LogOnInfo

          RepTblLogonInfo.ConnectionInfo = ConnInfo

          RepTbl.ApplyLogOnInfo(RepTblLogonInfo)

        Next

        Session("Rep") = rep

      End If

     

      Me.CrystalReportViewer1.ReportSource = Session("Rep")

      Me.CrystalReportViewer1.DataBind()

    End Sub

    Add the following code to bind the report for every button click and also during the page load event:

    Protected Sub btnFirst_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFirst.Click

      BindReport()

      Me.CrystalReportViewer1.ShowFirstPage()

    End Sub

     

    Protected Sub btnLast_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLast.Click

      BindReport()

      Me.CrystalReportViewer1.ShowLastPage()

    End Sub

     

    Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click

      BindReport()

      Me.CrystalReportViewer1.ShowNextPage()

    End Sub

     

    Protected Sub btnPrev_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrev.Click

      BindReport()

      Me.CrystalReportViewer1.ShowPreviousPage()

    End Sub

     

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

      If Not IsPostBack Then

        BindReport()

      End If

    End Sub

    I hope you enjoyed the article and any suggestions, bugs, errors, enhancements etc. are highly appreciated at http://jagchat.spaces.live.com


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hello guys,This is first in the series focusing on "Progamming with Crystal...
       · Hi,This is first in series focusing on "Programming Crystal Reports with ASP.NET...
       · Good Stuff here so far. Would like to see things get more advanced! Thanks for...
       · Hithis is 1 day in new project, I dn't know the ABC of Crystal report, I read your...
       · I would like information on how to set the web server up to run the crystal reports...
       · This article is very fine to activate CR in website.If u give details about CR...
       · This is one of the best tutorials on setting up Crystal Reports within a .Net and...
       · hi i m ajit.. working on crystalln reports . i put the data in crystal report...
       · I have found this article very useful for me as beginner :),,,,,,,,,, hope u'll be...
       · Thank you Jagadish,This was like buying something that works out of the...
       · Hi Sir, this Artical is Very Nice.Thank you.kamala
       · Hi Jag,Thank you very much for this article. After several hours of searching...
       · Hi sir,Thanks for posting, but while i run the application page6(i.e dynamically...
       · Hi Jagan,thanks a ton for the information provided..do you any have clue on how we...
       · it is avery useful article
       · Hi Sir Thank you for posting such an Imporatant and Useful Tutorial on Crystal...
       · we set "EnableParameterPrompt="False"". I apprecite if you can explain how pass...
       · Hi Sr.Thank for Your Contributions.I have a problem with this code Dim...
       · First thanks for sharing.I want choose a crystal report from a dropdownlist but...
     

    ASP.NET ARTICLES

    - Adding Content to a Static ASP.NET Website
    - Building a Static ASP.NET Website in a Basic...
    - Develop Your First ASP.NET Website with Visu...
    - Run ASP.NET in Windows XP Home with Cassini ...
    - How to Test a Web Application
    - How to Add Code and Validation Controls to a...
    - Working in Source and Split Views to Build a...
    - How to Build a Web Form for a One-Page Web A...
    - How to Develop a One-Page Web Application
    - An ASP.NET Web Application in Action
    - Developing ASP.NET Web Applications
    - An Introduction to ASP.NET Web Programming
    - Introduction to the ADO.NET Entity Framework...
    - Completing an In-Text Advertising System und...
    - Programming an In-Text Advertising System un...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek