Replace the contents of the code-behind file Default.aspx.cs with the C# code below.
usingBarcodeLib.Barcode;usingMicrosoft.Reporting.WebForms;usingBarcodeLib.Barcode.RDLCReports;usingSystem;usingSystem.Collections.Generic;usingSystem.Data;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Drawing.Imaging;namespaceBarcodeLibRDLCBarcodeAspnetDemo{publicpartialclassDefault:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){if(!IsPostBack){// Prepare report data.DataTabledt=newDataTable();dt.Columns.Add("Website",typeof(String));dt.Columns.Add("Barcode",typeof(byte[]));Stringid1="https://www.barcodelib.com";Stringid2="https://www.google.com/";Stringid3="https://www.youtube.com/";// Create data for the 1st row in the table.LinearRDLCbarcode=newLinearRDLC();barcode.Type=BarcodeType.CODE128;barcode.ImageWidth=600;barcode.ImageHeight=100;barcode.ImageFormat=ImageFormat.Png;barcode.Data=id1;byte[]imgData=barcode.drawBarcodeAsBytes();dt.Rows.Add(id1,imgData);// Create data for the 2nd row in the table.barcode.Data=id2;imgData=barcode.drawBarcodeAsBytes();dt.Rows.Add(id2,imgData);// Create data for the 3rd row in the table.barcode.Data=id3;imgData=barcode.drawBarcodeAsBytes();dt.Rows.Add(id3,imgData);// Configure ReportReportDataSourcerds=newReportDataSource("DataSet1",dt);this.ReportViewer1.LocalReport.DataSources.Clear();this.ReportViewer1.LocalReport.DataSources.Add(rds);this.ReportViewer1.LocalReport.ReportPath=Server.MapPath("~/Report1.rdlc");this.ReportViewer1.LocalReport.Refresh();}}}}
3.5 Configure the Web.config File
Copy all contents within the and configuration tags into the application's Web.config file.
<?xml version="1.0" encoding="utf-8"?><!-- For more information on how to configure your ASP.NET application, please visit https://go.microsoft.com/fwlink/?LinkId=169433 --><configuration><system.web><compilationdebug="true"targetFramework="4.7.2"><assemblies><!-- All assemblies updated to version 15.0.0.0. --><addassembly="Microsoft.ReportViewer.Common, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/><addassembly="Microsoft.ReportViewer.DataVisualization, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/><addassembly="Microsoft.ReportViewer.Design, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/><addassembly="Microsoft.ReportViewer.ProcessingObjectModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/><addassembly="Microsoft.ReportViewer.WebDesign, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/><addassembly="Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/><addassembly="Microsoft.ReportViewer.WinForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/></assemblies><buildProviders><!-- Version updated to 15.0.0.0. --><addextension=".rdlc"type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/></buildProviders></compilation><httpRuntimetargetFramework="4.7.2"/><httpHandlers><!-- Version updated to 15.0.0.0 --><addpath="Reserved.ReportViewerWebControl.axd"verb="*"type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"validate="false"/></httpHandlers></system.web><system.webServer><validationvalidateIntegratedModeConfiguration="false"/><modulesrunAllManagedModulesForAllRequests="true"/><handlers><!-- Version updated to 15.0.0.0 --><addname="ReportViewerWebControlHandler"preCondition="integratedMode"verb="*"path="Reserved.ReportViewerWebControl.axd"type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/></handlers></system.webServer></configuration>
4. Run the RDLC Report in the ASP.NET Application
Press Ctrl+F5 to execute the project.
The RDLC report with barcode images generated from the DataTable. will be displayed via the ReportViewer control.
A screenshot of the resulting RDLC report demo in the ASP.NET application is shown for reference.