Use Report Viewer In ASP.NET Using C#

Initial chamber

Step 1: Open Visual Studio 2010 and create an Empty Website. Give it a suitable name, reportview_demo.

Step 2: In Solution Explorer you get your empty website, then add a Web Form SQL Server Database, View and Dataset. By going like the following:

For Web Form:

reportview_demo(Your Empty Website) - Right Click,  Add New Item, then Web Form. Name it reportview_demo.aspx.

For SQL Server Database:

reportview_demo(Your Empty Website) - Right Click, Add New Item, then SQL Server Database. Add Database inside the App_Data_folder.

For DataSet:

reportview_demo (Your Empty Website) - Right Click, Add New Item, DataSet. Add DataSet inside the App_Code_folder.

Database chamber

Step 3: In Server Explorer, click on your database [Database.mdf] - Tables, Add New Table and make table like the following:

Table - tbl_data (Don’t Forget to make ID as IS Identity -- True)

table design

View - View_tbl_data

table
Double click on the dataset that resides under App_code_Folder. Here's the image:

dataset1

When you double click the dataset you get the blank area, there you have to do something like the following:
Right click on the blank area, Add, then DataTable.

add datatable

datatable 1

Change the name of the table from Datatable1 to Newtbl_data, there you have to add 3 columns for ID, Name, City as we had taken in tbl_data. So add three Columns and you will get the following:

tbl_data

Add three Columns and you will get something like the following image:

After this process you have to go to the reportview_demo - Right Click, Add New Item, then find Report.rdlc file.

Find Report

Right Click on Report - Insert table, then database properties window will open. In that select your DataSet and table.

dataset

After pressing OK in report.rdlc you will see Header and Data. In data row, right click and add the respective column as – ID, Name, City. You will see something like the following image:

column

Design chamber

Step 4: Now open your reportview_demo.aspx file, where we create our design for report viewer. We will add Report Viewer here.

Go to the toolbox and find Reporting. Drag and Drop Report Viewer.

reportview_demo.aspx

reportview_demo

Now add Report.rdlc from Choose Report.

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>  
  2.   
  3. <%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>  
  4.   
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  6.   
  7. <html xmlns="http://www.w3.org/1999/xhtml">  
  8. <head runat="server">  
  9.     <title></title>  
  10. </head>  
  11. <body>  
  12.     <form id="form1" runat="server">  
  13.     <asp:ScriptManager ID="ScriptManager1" runat="server">  
  14.     </asp:ScriptManager>  
  15.     <div>  
  16.       
  17.         <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana"   
  18.             Font-Size="8pt" InteractiveDeviceInfos="(Collection)"   
  19.             WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt">  
  20.             <LocalReport ReportPath="Report.rdlc">  
  21.                 <DataSources>  
  22.                     <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1" />  
  23.                 </DataSources>  
  24.             </LocalReport>  
  25.         </rsweb:ReportViewer>  
  26.         <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"   
  27.             SelectMethod="GetData"   
  28.             TypeName="DatabaseDataSetTableAdapters.tbl_dataTableAdapter">  
  29.         </asp:ObjectDataSource>  
  30.       
  31.     </div>  
  32.     </form>  
  33. </body>  
  34. </html>  
Output chamber

result

Hope you liked it. Thank you for reading. Have a good day!

 

Up Next
    Ebook Download
    View all
    Learn
    View all