我有一个asp.net报表查看器的问题我必须显示两个SQL表数据
我为此制作了一个功能,可以正常使用html报告,但我想在我的网站的报告查看器中显示它。 以下代码适用于Gridview,但不能与报表查看器绑定。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
reports();
}
}
private void reports()
{
DataSet ds = new DataSet();
DataTable da = new DataTable();
DataColumn dc = new DataColumn();
db.CommandTimeout = 200;
var ans = (from data in db.tblAttributeDatas
where data.nMainDataId == 3291
select data).ToList();
List<tblSectionAttribute> cols = (from Attrib in db.tblSectionAttributes
from main in db.tblAttributeDatas
where Attrib.nId == main.nSectionAttributeId
&&
main.nMainDataId == 3291
select Attrib).ToList();
int a = 1;
foreach (var item in cols)
{
DataColumn dc1 = new DataColumn(a.ToString() + "." + item.strAttributeName);
dc1.DefaultValue = "";
da.Columns.Add(dc1);
a++;
}
int row = 0;
DataRow dr = da.NewRow();
foreach (var item1 in ans)
{
DataColumn d = new DataColumn();
if (item1.strValue != "")
{
d = new DataColumn(row.ToString() + "." + item1.strValue);
}
else
{
d = new DataColumn("not Answered");
}
dr[row] = d;
//da.Rows.Add(dr);
// dr = da.Rows[row];
row++;
}
da.Rows.Add(dr);
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc");
ReportDataSource datasource = new ReportDataSource("DataSet",da);
ReportViewer1.DataBind();
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);
}
我的aspx代码是
<asp:ScriptManager runat="server" />
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt">
<LocalReport ReportPath="Report.rdlc">
<DataSources>
<rsweb:ReportDataSource />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
并且输出为空白只有空白ReportViewer在浏览器中显示,报表查看器内置标题和分页没有错误只是报表查看器的黑色输出 请帮忙
答案 0 :(得分:0)
并设计您的报告,只需将您的数据表字段拖放到rdlc文件中
即可我希望这些信息可以帮助你