Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am stucked at this RDLC for hours now. I want to load two rdlc reports in one report viewer, I want header at the start of a new report, please don't recommend sub reports.

What I have tried:

.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Services;
using System.IO;
using System.Data.Sql;
using Microsoft.Reporting.WebForms;

public partial class rdlc : System.Web.UI.Page
{
DataSet DsStockist = new DataSet();
DataTable dtDsStockist = new DataTable();
DataSet DsStockist2 = new DataSet();
DataTable dtDsStockist2 = new DataTable();

string conn = ConfigurationManager.ConnectionStrings["sqlcon"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
BindGrid2();
binddropdown1();
}
}
public void BindGrid()
{
DataSet DsStockist = new DataSet();
DataTable dtDsStockist = new DataTable();
string StrQrry = "";
StrQrry = "SELECT * From task";

string conn = ConfigurationManager.ConnectionStrings["sqlcon"].ConnectionString;
SqlDataAdapter adpRpt = new SqlDataAdapter(StrQrry, conn);
adpRpt.Fill(DsStockist, "DsStockist");
adpRpt.Fill(dtDsStockist);


if (DsStockist.Tables[0].Rows.Count > 0)
{
GrdStockist.DataSource = dtDsStockist;

GrdStockist.DataBind();
}
}
public void BindGrid2()
{
DataSet DsStockist2 = new DataSet();
DataTable dtDsStockist2 = new DataTable();
string StrQrry2 = "";
StrQrry2 = "SELECT * From client";

string conn = ConfigurationManager.ConnectionStrings["sqlcon"].ConnectionString;
SqlDataAdapter adpRpt2 = new SqlDataAdapter(StrQrry2, conn);
adpRpt2.Fill(DsStockist2, "DsStockist2");
adpRpt2.Fill(dtDsStockist2);


if (DsStockist2.Tables[0].Rows.Count > 0)
{
GridView2.DataSource = dtDsStockist2;

GridView2.DataBind();
}
}
protected void ShowRDLC(object sender, EventArgs e)
{
string conn = ConfigurationManager.ConnectionStrings["sqlcon"].ConnectionString;
string StrQrry = "";
StrQrry = "SELECT * From task";

SqlDataAdapter adpRpt = new SqlDataAdapter(StrQrry, conn);
adpRpt.Fill(DsStockist, "DsStockist");
adpRpt.Fill(dtDsStockist);
if (DsStockist.Tables[0].Rows.Count > 0)
{
GrdStockist.DataSource = dtDsStockist;

GrdStockist.DataBind();
}
string StrQrry2 = "";
StrQrry2 = "SELECT * From client";

SqlDataAdapter adpRpt2 = new SqlDataAdapter(StrQrry2, conn);
adpRpt2.Fill(DsStockist2, "DsStockist2");
adpRpt2.Fill(dtDsStockist2);


if (DsStockist2.Tables[0].Rows.Count > 0)
{
GridView2.DataSource = dtDsStockist2;

GridView2.DataBind();
}
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc");
ReportDataSource datasource = new ReportDataSource("DataSet1", DsStockist.Tables[0]);
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report2.rdlc");
ReportDataSource datasource2 = new ReportDataSource("DataSet2", DsStockist2.Tables[0]);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);
ReportViewer1.LocalReport.DataSources.Add(datasource2);

}
public override void VerifyRenderingInServerForm(Control control)
{
//required to avoid the runtime error "
//Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server."
}


protected void EcxelBtn_Click(object sender, EventArgs e)
{

ExportGridToExcel();
}
private void ExportGridToExcel()
{

}
public void binddropdown1()
{

}

protected void SelectedIndexChanged(object sender, EventArgs e)
{

}

protected void Add_Click(object sender, EventArgs e)
{
}
}
//////////////////////
aspx
///////////////////////////////////////

<%@ Page Title="" Language="C#" MasterPageFile="~/dv.master" AutoEventWireup="true" CodeFile="rdlc.aspx.cs" Inherits="rdlc" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>

<asp:content id="Content1" contentplaceholderid="head" runat="Server">


<asp:content id="Content2" contentplaceholderid="ContentPlaceHolder1" runat="server">





<asp:panel id="Panel1" cssclass="Panell" runat="server" width="1060px" height="31px">

RDLC





<asp:dropdownlist id="ddlclient" width="150px" runat="server">

<asp:button id="Button1" runat="server" cssclass="addbtn" width="100px"
="" height="35px" text="Add" onclick="Add_Click">


$('#<%=ddlclient.ClientID %>').chosen();

<asp:label id="lbltxt" text="" runat="server">




<asp:gridview id="GrdStockist" runat="server" autogeneratecolumns="false"
="" headerstyle-backcolor="#0d9dbc" height="50px" width="100%">
<columns>
<asp:boundfield datafield="client_id" itemstyle-width="120px" itemstyle-horizontalalign="Center" headertext="Client Id">
<asp:boundfield datafield="client_name" itemstyle-width="120px" itemstyle-horizontalalign="Center" headertext="Client Name">
<asp:boundfield datafield="activities" itemstyle-width="120px" itemstyle-horizontalalign="Center" headertext="Activites">
<asp:boundfield datafield="start_dt" itemstyle-width="120px" itemstyle-horizontalalign="Center" headertext="Start Date">
<asp:boundfield datafield="end_dt" itemstyle-width="120px" itemstyle-horizontalalign="Center" headertext="End Date">
<asp:boundfield datafield="remarks" itemstyle-width="120px" itemstyle-horizontalalign="Center" headertext="Remarks">


<asp:gridview id="GridView2" runat="server" autogeneratecolumns="false"
="" headerstyle-backcolor="#0d9dbc" headerstyle-bordercolor="#f2f2f2" height="50px" width="100%">
<columns>
<asp:boundfield datafield="client_id" itemstyle-width="120px" itemstyle-horizontalalign="Center" headertext="Client Id">
<asp:boundfield datafield="client_name" itemstyle-width="120px" itemstyle-horizontalalign="Center" headertext="Client Name">
<asp:boundfield datafield="pro_id" itemstyle-width="120px" itemstyle-horizontalalign="Center" headertext="Product Id">
<asp:boundfield datafield="pro_name" itemstyle-width="120px" itemstyle-horizontalalign="Center" headertext="Product Name">


<asp:button id="btnShow" cssclass="btn1" text="Show in Report"
="" runat="server" onclick="ShowRDLC">
<rsweb:reportviewer id="ReportViewer1" cssclass="align" runat="server" width="100%">



<asp:scriptmanager id="ScriptManager1" runat="server">


Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900