Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Crystal reports need to open in New window and should be in PDF how to do ??i pasted my code see below.
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Web
Imports CrystalDecisions.Shared
Partial Class crs_fullcyl
    Inherits System.Web.UI.Page
  
    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        'DropDownList1.Text = "Full Cylinders Report"
        'TxtToDt.Text = ""
        'TxtToDt0.Text = ""
        CrystalReportViewer1.Visible = False
        'CrystalReportViewer1.Dispose()
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Response.Redirect("cylinder_report.aspx?report=" & Left(DropDownList1.SelectedItem.Value, 4))
        'Response.Redirect("cylinder_report.aspx?report=" & Left(DropDownList1.SelectedItem.Value, 4))
        If Page.IsPostBack Then
            CrystalReportViewer1.Visible = True
        Else
            CrystalReportViewer1.Visible = False
        End If
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim RptDocument As New ReportDocument
        RptDocument.Load(Server.MapPath("FullCycleReport1.rpt"))

        Dim flag As String = String.Empty
        If (String.Equals(DropDownList1.SelectedItem.Value, "Full Cylinders Report")) Then
            flag = "F"
        ElseIf (String.Equals(DropDownList1.SelectedItem.Value, "Empty Cylinders Report")) Then
            flag = "E"
        ElseIf (String.Equals(DropDownList1.SelectedItem.Value, "ISSUED Cylinders Report")) Then
            flag = "I"
        Else
            flag = "R"
        End If

        'Set login info
        Dim myLogin As CrystalDecisions.Shared.TableLogOnInfo
        'Dim RptDocument As New ReportDocument
        Dim myTable As Table
        For Each myTable In RptDocument.Database.Tables
            myLogin = myTable.LogOnInfo
            myLogin.ConnectionInfo.ServerName = "VANARAJ\SQLEXPRESS"
            myLogin.ConnectionInfo.DatabaseName = "Hr"
            myLogin.ConnectionInfo.UserID = "sa"
            myLogin.ConnectionInfo.Password = "Password1*"
            myTable.ApplyLogOnInfo(myLogin)
            myTable.Location = myTable.Location
        Next
        CrystalReportViewer1.ReportSource = RptDocument
        If Not IsPostBack = True Then
            TxtToDt.Text = Format(Now, "yyyy-MM-dd")
            TxtToDt0.Text = Format(Now, "yyyy-MM-dd")
        End If
        'Dim RptDocument As New ReportDocument
        RptDocument.Load(Server.MapPath("FullCycleReport1.rpt"))

        'Dim flag As String = String.Empty
        If (String.Equals(DropDownList1.SelectedItem.Value, "Full Cylinders Report")) Then
            flag = "F"
        ElseIf (String.Equals(DropDownList1.SelectedItem.Value, "Empty Cylinders Report")) Then
            flag = "E"
        ElseIf (String.Equals(DropDownList1.SelectedItem.Value, "ISSUED Cylinders Report")) Then
            flag = "I"
        Else
            flag = "R"
        End If

        RptDocument.SetParameterValue(0, TxtToDt.Text)
        RptDocument.SetParameterValue(1, TxtToDt0.Text)
        RptDocument.SetParameterValue(2, flag)

    End Sub
End Class</pre>

ASP CODE
<pre><%@ Page Language="VB" MasterPageFile="~/MasterPage2.master" AutoEventWireup="false"
    CodeFile="crs_fullcylreport.aspx.vb" Inherits="crs_fullcyl" Title="Cylinders Report" %>

<%@ Register Assembly="CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
    Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder2" runat="Server">
    <p>
        <img alt="Report" src="Images/report.jpg" style="width: 140px; height: 189px" /></p>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <br />
    You are here
    <asp:SiteMapPath ID="SiteMapPath1" runat="server" Font-Names="Verdana" Font-Size="0.8em"
        PathSeparator=" : ">
        <pathseparatorstyle font-bold="True" forecolor="#990000" />
        <currentnodestyle forecolor="#333333" />
        <nodestyle font-bold="True" forecolor="#990000" />
        <rootnodestyle font-bold="True" forecolor="#FF8000" />
    

<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder3" runat="Server">
    <table cellpadding="0" cellspacing="0" width="100%" border="1" bordercolor="gray">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
            <contenttemplate>
                <tr>
                    <td width="100%" bgcolor="gray">
                        <div id="gasreporthead" align="center">
                            <h1>
                                Gas Return
                            </h1>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td width="100%">
                        <div id="maincontent">
                            <table cellpadding="0" cellspacing="15" width="100%">
                                <tr>
                                    <td width="25%">
                                        <asp:Label ID="Label3" runat="server" Text="Label">To Status
                                    </td>
                                    <td width="30%">
                                        <asp:DropDownList ID="DropDownList1" runat="server" Height="20px" Width="225px">
                                            <asp:ListItem>Full Cylinders Report
                                            <asp:ListItem>Empty Cylinders Report
                                            <asp:ListItem>ISSUED Cylinders Report
                                            <asp:ListItem>Returned To Supplier
                                        
                                        <asp:ScriptManager ID="ScriptManager1" runat="server">
                                        
                                    </td>
                                </tr>
                                <tr>
                                    <td width="25%">
                                        <asp:Label ID="Label1" runat="server" Text="Label">From Date
                                    </td>
                                    <td width="30%">
                                        <asp:TextBox ID="TxtToDt" runat="server" Height="18px" Font-Size="Small" Width="150px">
                                        <cc1:CalendarExtender ID="TxtToDt_CalendarExtender"  runat="server" Format="yyyy-MM-dd"
                                            Enabled="True" TargetControlID="TxtToDt">
                                        
                                    </td>
                                    <td width="25%">
                                        <asp:Label ID="Label2" runat="server" Text="Label">To Date
                                    </td>
                                    <td width="20%">
                                        <asp:TextBox ID="TxtToDt0" runat="server" Height="18px" Font-Size="Small" Width="150px">
                                        <cc1:CalendarExtender ID="TxtToDt0_CalendarExtender"  runat="server" Format="yyyy-MM-dd"
                                            Enabled="True" TargetControlID="TxtToDt0">
                                        
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td align="center">
                        <table>
                            <tr>
                                <td width="40%">
                                    <asp:Button ID="Button1" runat="server" Font-Bold ForeColor="DarkRed" Text="Report" />
                                </td>
                                <td width="40%">
                                    <asp:Button ID="Button2" runat="server" Font-Bold ForeColor="DarkRed" Style="height: 26px"
                                        Text="Reset" />
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <%-- <table>--%>
                <tr>
                    <td>
                        <CR:CrystalReportViewer ID="CrystalReportViewer1"  runat="server" AutoDataBind="true"
                            HasToggleGroupTreeButton="False" DisplayGroupTree="False" HasViewList="False" Visible="false" EnableDrillDown="false" />
                    </td>
                </tr>
                <%-- </table>--%>
            </contenttemplate>
        
        <%--  <asp:UpdatePanel ID="panelCrystalReport" runat="server">
            <contenttemplate>
                
            </contenttemplate>
        --%>
    </table>
Posted
Updated 6-Jun-14 2:56am
v3

1 solution

use this code is better efficient and more easy

VB
cryRpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, True, "ExportedReport")


if change from true to false open in the same page else show dialog open or save to open it in new windows.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900