Crystal报表需要在新窗口中打开并且应该用PDF格式化怎么办?我粘贴了我的代码见下文 [英] Crystal reports need to open in New window and should be in PDF how to do ?i pasted my code see below

查看:64
本文介绍了Crystal报表需要在新窗口中打开并且应该用PDF格式化怎么办?我粘贴了我的代码见下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Crystal报表需要在新窗口中打开并且应该是PDF格式怎么办?我粘贴了我的代码见下文。

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>

推荐答案

使用此代码更高效,更轻松



use this code is better efficient and more easy

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





如果从true为false在同一页面中打开,否则显示对话框打开或保存以在新窗口中打开它。



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


这篇关于Crystal报表需要在新窗口中打开并且应该用PDF格式化怎么办?我粘贴了我的代码见下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆