回复 2楼frank.zhang的帖子
后台代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace WebApplication1
{
public partial class 运行时加载数据2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
setReport();
}
protected void runtime_LocateDataSource(object sender, GrapeCity.ActiveReports.LocateDataSourceEventArgs args)
{
if (args.DataSourceName == "DataSource1")
{
if (args.DataSetName == "DataSet1")
{
args.Data = GetDataSource();
}
}
}
private DataTable GetDataSource()
{
DataTable dt = new DataTable();
dt.Columns.Add("name");
dt.Rows.Add("苹果");
dt.Rows.Add("香蕉");
dt.Rows.Add("菠萝");
return dt;
}
private void setReport()
{
string url = "setWebDataReport.rdlx";
GrapeCity.ActiveReports.PageReport report1 = null;
report1 = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("报表/" + url)));
GrapeCity.ActiveReports.Document.PageDocument runtime = new GrapeCity.ActiveReports.Document.PageDocument(report1);
runtime.LocateDataSource += new GrapeCity.ActiveReports.LocateDataSourceEventHandler(runtime_LocateDataSource);
WebViewer1.Report = runtime;
}
}
}
前台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="运行时加载数据2.aspx.cs" Inherits="WebApplication1.运行时加载数据2" %>
<%@ Register Assembly="GrapeCity.ActiveReports.Web.v9, Version=9.0.1678.0, Culture=neutral, PublicKeyToken=096a9279a87304f1"
Namespace="GrapeCity.ActiveReports.Web" TagPrefix="ActiveReportsWeb" %>
<!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>
<ActiveReportsWeb:WebViewer ID="WebViewer1" runat="server" Height="100%" Width="100%"
ViewerType="FlashViewer">
</ActiveReportsWeb:WebViewer>
</div>
</form>
</body>
</html>
这样写的不报错,但是前台数据集加载不上数据,帮忙看看是什么原因 |