In this article I will explain with an example, how to display (show) GridView data in RDLC report in ASP.Net using C# and VB.Net.
When the Button is clicked, the data from the rows of the GridView for which the CheckBox is checked (selected) will be copied to the Typed DataSet object and then the object of the Typed DataSet will be used to populate the RDLC report.
 
 
Database
Here I am making use of Microsoft’s Northwind Database. You can download it from here
 
 
Configuring the RDLC report and populating from database
The very first step is to add and configure a RDLC report and connect it with Typed DataSet. For more details, please refer my article RDLC (Local SSRS) report ASP.Net Example.
Following is the designed RDLC report which will be later populated using GridView data in ASP.Net.
Display (Show) GridView data in RDLC Report in ASP.Net using C# and VB.Net
 
 
HTML Markup
The HTML Markup consists of an ASP.Net AJAX ScriptManager control, a GridView, a Button and a ReportViewer control.
Note: The ReportViewer control requires ScriptManager control on the page.
 
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" CssClass="Grid">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:CheckBox ID="chkSelect" runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="CustomerId" HeaderText="Customer Id" />
            <asp:BoundField DataField="ContactName" HeaderText="Contact Name" />
            <asp:BoundField DataField="City" HeaderText="City" />
            <asp:BoundField DataField="Country" HeaderText="Country" />
        </Columns>
    </asp:GridView>
    <br />
    <asp:Button ID="btnShow" Text="Show in Report" runat="server" OnClick="ShowRDLC" />
    <hr />
    <rsweb:ReportViewer ID="ReportViewer1" runat="server" Width="600">
    </rsweb:ReportViewer>
    </form>
</body>
</html>
 
 
Namespaces
You will need to import the following namespaces.
C#
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.Reporting.WebForms;
 
VB.Net
Imports System.Data
Imports System.Configuration
Imports System.Data.SqlClient
Imports Microsoft.Reporting.WebForms
 
 
Populating the GridView from Database
Inside the Page Load event of the page, the GridView is populated using the records from the Database.
C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        gvCustomers.DataSource = GetData("SELECT TOP 5 * FROM Customers ORDER BY NEWID()");
        gvCustomers.DataBind();
    }
}
 
private DataTable GetData(string query)
{
    string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    SqlCommand cmd = new SqlCommand(query);
    using (SqlConnection con = new SqlConnection(conString))
    {
        using (SqlDataAdapter sda = new SqlDataAdapter())
        {
            cmd.Connection = con;
 
            sda.SelectCommand = cmd;
            using (DataTable dt = new DataTable())
            {
                sda.Fill(dt);
                return dt;
            }
        }
    }
}
 
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    If Not Me.IsPostBack Then
        gvCustomers.DataSource = GetData("SELECT TOP 5 * FROM Customers ORDER BY NEWID()")
        gvCustomers.DataBind()
    End If
End Sub
 
Private Function GetData(query As String) As DataTable
    Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
    Dim cmd As New SqlCommand(query)
    Using con As New SqlConnection(conString)
        Using sda As New SqlDataAdapter()
            cmd.Connection = con
 
            sda.SelectCommand = cmd
            Using dt As New DataTable()
                sda.Fill(dt)
                Return dt
            End Using
        End Using
    End Using
End Function
 
 
Display (Show) GridView data in RDLC report in ASP.Net
When the Button is clicked, an object of the Customers Typed DataSet is created. Then a loop is executed over the GridView rows and the data of the rows for which the CheckBox is checked (selected) are copied to the Customers Typed DataSet.
Finally the Customers Typed DataSet is used to populate the RDLC report.
C#
protected void ShowRDLC(object sender, EventArgs e)
{
    Customers dsCustomers = new Customers();
    foreach (GridViewRow row in gvCustomers.Rows)
    {
        if ((row.FindControl("chkSelect") as CheckBox).Checked)
        {
            string customerId = row.Cells[1].Text;
            string contactName = row.Cells[2].Text;
            string city = row.Cells[3].Text;
            string country = row.Cells[4].Text;
            dsCustomers.Tables[0].Rows.Add(row.Cells[1].Text, row.Cells[2].Text, row.Cells[3].Text, row.Cells[4].Text);
        }
    }
 
    ReportViewer1.ProcessingMode = ProcessingMode.Local;
    ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc");
    ReportDataSource datasource = new ReportDataSource("Customers", dsCustomers.Tables[0]);
    ReportViewer1.LocalReport.DataSources.Clear();
    ReportViewer1.LocalReport.DataSources.Add(datasource);
}
 
VB.Net
Protected Sub ShowRDLC(sender As Object, e As EventArgs)
    Dim dsCustomers As New Customers()
    For Each row As GridViewRow In gvCustomers.Rows
        If TryCast(row.FindControl("chkSelect"), CheckBox).Checked Then
            Dim customerId As String = row.Cells(1).Text
            Dim contactName As String = row.Cells(2).Text
            Dim city As String = row.Cells(3).Text
            Dim country As String = row.Cells(4).Text
            dsCustomers.Tables(0).Rows.Add(row.Cells(1).Text, row.Cells(2).Text, row.Cells(3).Text, row.Cells(4).Text)
        End If
    Next
 
    ReportViewer1.ProcessingMode = ProcessingMode.Local
    ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc")
    Dim datasource As New ReportDataSource("Customers", dsCustomers.Tables(0))
    ReportViewer1.LocalReport.DataSources.Clear()
    ReportViewer1.LocalReport.DataSources.Add(datasource)
End Sub
 
 
Screenshot
Display (Show) GridView data in RDLC Report in ASP.Net using C# and VB.Net
 
 
Demo
 
 
Downloads