locked
Looking for ASP.Net samples for selecting a Crystal Report from a dropdownlist value RRS feed

  • Question

  • User1416033902 posted

    Hi all,

    I am looking  for any sample in VB.Net or C# that explains how to select a Crystal Report from a ASP.Net dropdonwlist and open it with CrystalReportViewer.

    The report names  are going to be stored as ListItem in the dropdownlist.

    Tuesday, February 4, 2014 10:46 PM

All replies

  • User22205941 posted

    I think you know the how to create a crytal report.

    After creating list if crystal report, 

    Bind with these names and crystal report path into dropdown list.

    <asp:Dropdownlist id="ddlreport" runat="server">
       <asp:ListItem value="your path of crystalreport1" Text="CrystalReport1">
       <asp:ListItem value="your path of crystalreport2" Text="CrystalReport2">
       <asp:ListItem value="your path of crystalreport3" Text="CrystalReport3">
    </asp:dropdownlis>

    After that, in dropdown list selectedIndexChanged event,

    ReportDocument rpt = new ReportDocument();
    rpt.Load(Server.MapPath(ddlreport.SelectedValue));



     

    Tuesday, February 4, 2014 11:37 PM
  • User1416033902 posted

    hi

    I created a Crystal Reports VS 2010 web site using the template "ASP.NEt Crystal Reports web site" , and then customized adding a dropdownlist to the Default.aspx.

    PROBLEM: it always shows the same Report!!

     

    HTML code  for DropDownList

    body>
        <form id="form1" runat="server">
        <div>
           <asp:Label ID="Label1" runat="server" Text="Report:"></asp:Label>
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
                <asp:ListItem Selected="True" 
                    Value="SQLAAWithDetail.rpt">SQLAAWithMDetail</asp:ListItem>
                <asp:ListItem Value="SQLSummaryAAWithReservedA.rpt">SQLSummaryAA</asp:ListItem>
                <asp:ListItem Value="SQLSummaryADeA.rpt">SQLSummaryADeA</asp:ListItem>
                <asp:ListItem Value="SQLSummaryVFA.rpt">SQLSummaryVFormsA</asp:ListItem>
                <asp:ListItem Value="SQLVFWithDetail.rpt">SQLVFWithMDetail</asp:ListItem>
            </asp:DropDownList>
         
            <CR:CrystalReportViewer ID="CrystalReportViewer1" Runat="server" AutoDataBind="True"
                Height="947px" ReportSourceID="CrystalReportSource1" Width="845px" />
            <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
                <Report FileName="SQLAAWithMDetail.rpt">
                </Report>
            </CR:CrystalReportSource>
        
            
        
        </div>
        </form>
    </body>

    This is the code of the whole Default.aspx wep page.  I run the application in debug mode and the Dropdownbox works fine.

     

    What is missning?

     

    Imports CrystalDecisions.Web
    
    Partial Class _Default
        Inherits System.Web.UI.Page
    
        Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
            Dim CRsource As New CrystalReportSource
    
    
    
            CRsource.Report.FileName = DropDownList1.SelectedItem.Value
    
            '  Me.CrystalReportViewer1.RefreshReport()
    
            Me.CrystalReportViewer1.ReportSource = CRsource
    
    
            Me.CrystalReportViewer1.RefreshReport()
    
    
    
    
    
    
        End Sub
    End Class

    Wednesday, February 5, 2014 12:01 PM
  • User22205941 posted
    Dim reportdocument As New ReportDocument()
    reportdocument.Load(Server.MapPath("your selected value"))
    CrystalReportViewer1.ReportSource = reportdocument

    Wednesday, February 5, 2014 11:37 PM
  • User-578610739 posted
      CRsource.Report.FileName = DropDownList1.SelectedItem.Value  --you need to give full path here of your file location i.e. d:/project/report/abc.rpt
    to properly use
      CRsource.Report.FileName = server.mappath( DropDownList1.SelectedItem.Value  )

    http://www.aspsnippets.com/Articles/Crystal-Report-ASPNet-Example-using-DataSet-or-DataTable-in-C-VBNet-and-Visual-Studio-2010.aspx

    http://stackoverflow.com/questions/8341272/how-to-bind-crystal-report-to-manually-created-dataset

    http://docs.imis.com/20.0/index.htm#!addingcrystalreports2.htm

    Thursday, February 6, 2014 12:34 AM
  • User1416033902 posted

    Hi all,

     

    This is not the most optimun solution  but it works and allows me to understand how the Crystal Reports controls work together.

    This is what I  did! I just created a  CrystalReportSource per report and then the DropDownList1_SelectedIndexChanged works as expected.

     

    Take a look to the code below:

     

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
    <%@ Register TagPrefix="CR" Namespace="CrystalDecisions.Web" Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" %>
    
    <%@ Register assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>
    
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
           <asp:Label ID="Label1" runat="server" Text="Report:"></asp:Label>
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
                <asp:ListItem Selected="True" 
                    Value="Report1.rpt">Report1</asp:ListItem>
                <asp:ListItem Value="Report2.rpt">Report2</asp:ListItem>
                <asp:ListItem Value="Report3.rpt">Report3</asp:ListItem>
                <asp:ListItem Value="Report4.rpt">Report4</asp:ListItem>
                <asp:ListItem Value="Report5.rpt">Report5</asp:ListItem>
            </asp:DropDownList>
         
            <CR:CrystalReportViewer ID="CrystalReportViewer1" Runat="server" AutoDataBind="True"
                Height="962px" ReportSourceID="CrystalReportSource5" Width="1344px" 
                GroupTreeImagesFolderUrl="" ToolbarImagesFolderUrl="" 
                ToolPanelWidth="200px" />
            <CR:CrystalReportSource ID="CrystalReportSource5" runat="server">
    <report filename="Report5.rpt"></report>
    </CR:CrystalReportSource>
            <CR:CrystalReportSource ID="CrystalReportSource4" runat="server">
    <report filename="Report4.rpt"></report>
    </CR:CrystalReportSource>
            <CR:CrystalReportSource ID="CrystalReportSource3" runat="server">
    <report filename="Report3.rpt"></report>
    </CR:CrystalReportSource>
            <CR:CrystalReportSource ID="CrystalReportSource2" runat="server">
    <report filename="Report2.rpt"></report>
    </CR:CrystalReportSource>
            <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
                <Report FileName="Report5.rpt">
                </Report>
            </CR:CrystalReportSource>
           
        
            
        
        </div>
        </form>
    </body>
    </html>
    
    


    The VB.Net source code.

    Imports CrystalDecisions.Shared
    Imports CrystalDecisions.CrystalReports.Engine
    Imports CrystalDecisions.Web
    
    Partial Class _Default
        Inherits System.Web.UI.Page
    
        
       
    
        Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
            Dim CRsource As New CrystalReportSource
    
            Dim CRviewer As New CrystalReportViewer
    
            Dim strNameReport As String
    
            strNameReport = DropDownList1.SelectedItem.Text
    
    
            CRsource.Report.FileName = DropDownList1.SelectedItem.Value
    
            Select strNameReport
                Case "Report1"
                    Me.CrystalReportViewer1.ReportSourceID = "CrystalReportSource1"
    
                Case "Report2"
                    Me.CrystalReportViewer1.ReportSourceID = "CrystalReportSource2"
    
                Case "Report3"
                    Me.CrystalReportViewer1.ReportSourceID = "CrystalReportSource3"
    
                Case "Report4"
                    Me.CrystalReportViewer1.ReportSourceID = "CrystalReportSource4"
    
                Case "Report5"
                    Me.CrystalReportViewer1.ReportSourceID = "CrystalReportSource5"
    
    
            End Select
    
    
           
    
    
            Me.CrystalReportViewer1.RefreshReport()
    
    
    
    
    
    
        End Sub
    
        Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
            If (Page.IsPostBack) Then
                'Me.CrystalReportViewer1.Visible = True
            Else
                ' Me.CrystalReportViewer1.Visible = False
            End If
    
    
    
        End Sub
    End Class
    
    

     

     

     

     

    Thursday, February 6, 2014 8:32 AM