具体代码:
该页面前台:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="mPrintPage.aspx.cs" Inherits="mPrintPage" %>
<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>打印预览</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Height="100%" Width="100%">
</rsweb:ReportViewer>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
</div>
</form>
</body>
</html>
该页面后他
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
using System.Data;
using System.Configuration;
public partial class mPrintPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string tableName = Session["PrintTableName"].ToString();
if (tableName == "DateTableRep")
PrintStationDaySta();
}
}
protected void PrintStationDaySta()
{
string strStationDaySta = ConfigurationManager.AppSettings["StationDaySta"].ToString();
string mStartDayTime = "";
string mEndDayTime = "";
decimal totalWeight = 0, totalAmount = 0;
if (Session["startdaytime"].ToString() != null)
{
mStartDayTime = Session["startdaytime"].ToString();
}
if (Session["enddaytime"].ToString() != null)
{
mEndDayTime = Session["enddaytime"].ToString();
}
DataTable dt = new DataTable();
/*if (Session["PrintSqlTect"].ToString() != null)
{
string sql = Session["PrintSqlTect"].ToString();
ZSql zsql = new ZSql();
zsql.Open(sql);
dt = zsql.m_table;
}*/
//totalWeight = (decimal)Session["WeightVal"];
//totalAmount = (decimal)Session["AmountVal"]; ;
dt.Clear();
dt = (DataTable)Session["PrintTableDate"];
ReportViewer1.LocalReport.ReportPath = strStationDaySta;
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("dtDayStaMsg", dt));
string StrTable = Session["PrintTable"].ToString();
string StrTime = "统计时间:" + mStartDayTime + "~" + mEndDayTime;
string StrVal = Session["PrintLjVal"].ToString();
ReportParameter RpTable = new ReportParameter("ReportParameterTable", StrTable);
ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { RpTable });
ReportParameter RpTime = new ReportParameter("ReportParameteTime", StrTime);
ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { RpTime });
ReportParameter RpVal = new ReportParameter("ReportParameterVal", StrVal);
ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { RpVal });
ReportViewer1.LocalReport.Refresh();
}
打开该页面:
string url = "mPrintPage.aspx";
Response.Redirect(url);
6 个解决方案
#1
你建ReportViewer1这个报表文件没有?
#3
有报表的! 绝对
#4
哪位大侠指点一下啊 搞不定我就要下岗了 !
#5
PrintStationDaySta();单独放到Page_Load里报错吗
#6
没有啊
#1
你建ReportViewer1这个报表文件没有?
#2
Refer & try it:
http://www.cnblogs.com/insus/category/519581.html
http://www.cnblogs.com/insus/category/519581.html
#3
有报表的! 绝对
#4
哪位大侠指点一下啊 搞不定我就要下岗了 !
#5
PrintStationDaySta();单独放到Page_Load里报错吗
#6
没有啊