本帖最后由 wengMQ 于 2021-12-19 17:36 编辑
https://gcdn.grapecity.com.cn/showtopic-138503-1-1.html
第一步:
页面后端代码
protected void Page_Load(object sender, EventArgs e)
{
PageReport pageReport = new PageReport();
pageReport.Load(new FileInfo(AppContext.BaseDirectory + "Reports/ds.rdlx"));
ReportParameter DefPar = new ReportParameter();
DefPar = new ReportParameter();
DefPar.Name = "UserId";
DefPar.AllowBlank = true;
DefPar.DataType = ReportParameterDataType.String;
DefPar.Hidden = true;
DefPar.DefaultValue.Values.Add("123456");
pageReport.Report.ReportParameters.Add(DefPar);
arvWebMain.Report= pageReport.Report;
}
第二步 Global.asax.cs文件
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using GrapeCity.ActiveReports.PageReportModel;
using GrapeCity.ActiveReports.Web;
namespace GrapeCity.ActiveReports.Samples.Web
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
this.UseReporting(settings =>
{
settings.UseCompression = true;
settings.SetLocateDataSource(vr =>
{
ReportParameter UserId = GRPars(vr.Report, "UserId");
string strUserId = UserId.DefaultValue.Values[0].ToString();
DataTable dt = new DataTable();
dt.Columns.Add("A");
dt.Columns.Add("B");
dt.Rows.Add(Guid.NewGuid().ToString(""), Guid.NewGuid().ToString(""));
dt.Rows.Add(Guid.NewGuid().ToString(""), Guid.NewGuid().ToString(""));
dt.Rows.Add(Guid.NewGuid().ToString(""), Guid.NewGuid().ToString(""));
dt.Rows.Add(Guid.NewGuid().ToString(""), Guid.NewGuid().ToString(""));
dt.Rows.Add(Guid.NewGuid().ToString(""), Guid.NewGuid().ToString(""));
return dt;
});
});
}
private ReportParameter GRPars(Report CRpt, string parname)
{
ReportParameter rptpar = null;
try
{
for (int pi = 0; pi < CRpt.ReportParameters.Count; pi++)
{
if (CRpt.ReportParameters[pi].Name == parname)
{
return CRpt.ReportParameters[pi];
}
}
}
catch (Exception ex)
{
}
return rptpar;
}
}
}
|