Hello everyone,
I have a list of records, When I went to put my list in as a report data source to my rdlc report it said my datasource must be a data table or 2 other options it gave. I turned my list into a datatable and now when I insert that as my data source I get no errors and my controller action completes but my ‘return file’ never opens up a new report or anything for my record. If I try to just insert 1 record I get the report opened as an rdlc report.
<input type="button" class="btn btn-primary" name="command" id="btnGetChecks" value="Generate Selected" />
$('#btnGetChecks').on('click', function () {
var arrChkBoxes = [];
var arrSelectedQIDs = [];
var quoteid = $(this).attr("value");
var chkboxtable = $('#maintbl');
var chktablebody = chkboxtable.find('#maintblbody');
$("input:checked").each(function (index, value) {
arrChkBoxes.push($(value).val());
});
$.each(arrChkBoxes, function (key, value) {
if (IsPositiveInteger(value)) {
arrSelectedQIDs.push(value);
}
});
$.ajax({
type: "GET",
url: "/Service/GeneratePreviewReports/",
contentType: "application/json; charset=utf-8",
traditional: true,
data: { "quoteIDs": arrSelectedQIDs },
success: function () {
alert("success");
},
error: function (request, status, error) {
alert("error " + request.responseText);
}
});
});
public ActionResult GeneratePreviewReports(int[] quoteIDs)
{
List<ServiceQuote> lstQuotes = new List<ServiceQuote>();
if(quoteIDs != null)
{
foreach(var qid in quoteIDs)
{
var quote = context.ServiceQuotes.Where(x => x.QuoteID == qid).FirstOrDefault();
lstQuotes.Add(quote);
}
}
LocalReport localReport = new LocalReport()
{
ReportPath = Server.MapPath("~/ReportForms/VirtualService3.rdlc")
};
List<TRACKER_TESTDataSet.Service_FieldsRow> rows = new List<TRACKER_TESTDataSet.Service_FieldsRow>();
foreach(var item in lstQuotes)
{
var itemTable = CreateDT(item);
ReportDataSource reportDataSource = new ReportDataSource("Service_Fields", itemTable);
localReport.DataSources.Add(reportDataSource);
string command = "PDF";
string reportType = command;
string mimeType, encoding, fileNameExtension;
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>" + command + "</OutputFormat>" +
" <PageWidth>8.5in</PageWidth>" +
" <PageHeight>11in</PageHeight>" +
" <MarginTop>0.5in</MarginTop>" +
" <MarginLeft>0.3in</MarginLeft>" +
" <MarginRight>0.3in</MarginRight>" +
" <MarginBottom>0.5</MarginBottom>" +
"</DeviceInfo>";
Warning[] warnings;
string[] streams;
byte[] renderedBytes;
renderedBytes = localReport.Render(reportType, deviceInfo, out mimeType, out encoding, out fileNameExtension, out streams, out warnings);
return File(renderedBytes, mimeType);
}
return RedirectToAction("VirtualService");
}
private DataTable CreateDT(object obj)
{
if(obj != null)
{
Type t = obj.GetType();
DataTable dt = new DataTable(t.Name);
foreach(PropertyInfo pi in t.GetProperties())
{
dt.Columns.Add(new DataColumn(pi.Name));
}
DataRow dr = dt.NewRow();
foreach(DataColumn dc in dt.Columns)
{
dr[dc.ColumnName] = obj.GetType().GetProperty(dc.ColumnName).GetValue(obj, null);
}
dt.Rows.Add(dr);
return dt;
}
return null;
}
What I have tried:
When I have 1 record my report is displayed but now I would like multiple reports 1 for each item in the list or just 1 report with each item 1 after another in the same rdlc file. My code executes and my ajax goes to 'success' but the rdlc doesn't open.