Hi kankon,
Using below aticle i have created the example.
For sending the data to popup page i am using Session and set the row which need to display in RDLC. Then in popup page bing the record to RDLC.
Refer below code.
HTML
Details
<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" />
<asp:TemplateField HeaderText="Print">
<ItemTemplate>
<asp:Button ID="btnNewWindow" runat="server" Text="Print" OnClick="OpenWindow"></asp:Button>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="100px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
Default
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Width="600">
</rsweb:ReportViewer>
Namespaces
C#
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.Reporting.WebForms;
VB.Net
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.Reporting.WebForms
Code
C#
Details
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;
}
}
}
}
protected void OpenWindow(object sender, EventArgs e)
{
Session["GridViewRow"] = (sender as Button).NamingContainer as GridViewRow;
string url = "Default.aspx";
string s = "window.open('" + url + "', 'popup_window', 'width=600,height=800,left=100,top=100,resizable=yes');";
ClientScript.RegisterStartupScript(this.GetType(), "script", s, true);
}
Default
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["GridViewRow"] != null)
{
Customers dsCustomers = new Customers();
GridViewRow row = Session["GridViewRow"] as GridViewRow;
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
Details
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
Protected Sub OpenWindow(ByVal sender As Object, ByVal e As EventArgs)
Session("GridViewRow") = TryCast((TryCast(sender, Button)).NamingContainer, GridViewRow)
Dim url As String = "Default.aspx"
Dim s As String = "window.open('" & url & "', 'popup_window', 'width=600,height=800,left=100,top=100,resizable=yes');"
ClientScript.RegisterStartupScript(Me.GetType(), "script", s, True)
End Sub
Default
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
If Session("GridViewRow") IsNot Nothing Then
Dim dsCustomers As Customers = New Customers()
Dim row As GridViewRow = TryCast(Session("GridViewRow"), GridViewRow)
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)
ReportViewer1.ProcessingMode = ProcessingMode.Local
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc")
Dim datasource As ReportDataSource = New ReportDataSource("Customers", dsCustomers.Tables(0))
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.DataSources.Add(datasource)
End If
End If
End Sub
Screenshot