Hi Firuz,
I have created one sample that full-fill your requirement.
SQL
CREATE PROCEDURE GetEmployees
AS
BEGIN
DECLARE @MyEmployees AS TABLE(EmployeeID VARCHAR(50), Title VARCHAR(50), ManagerID VARCHAR(50),EmployeeLevel INT)
INSERT INTO @MyEmployees VALUES('M001','HR System',NULL,0)
INSERT INTO @MyEmployees VALUES('M002','Payroll','M001',1)
INSERT INTO @MyEmployees VALUES('M003','Salary Benefits','M002',2)
INSERT INTO @MyEmployees VALUES('M004','Recruitment','M001',1)
;WITH DirectReports(ManagerID,EmployeeID,Title,EmployeeLevel)
AS
(
SELECT ManagerID,EmployeeID,Title,0 AS EmployeeLevel FROM @MyEmployees WHERE ManagerID IS NULL
UNION ALL
SELECT me.ManagerID,me.EmployeeID,me.Title,(me.EmployeeLevel + 1) AS EmployeeLevel FROM @MyEmployees me
INNER JOIN DirectReports d ON d.EmployeeID = me.ManagerID
)
SELECT ManagerID,EmployeeID,Title,EmployeeLevel FROM DirectReports WHERE EmployeeLevel <= 2
END
HTML
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Width="600">
</rsweb:ReportViewer>
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/EmployeesReport.rdlc");
Employees dsEmployees = GetData("GetEmployees");
ReportDataSource datasource = new ReportDataSource("Employees", dsEmployees.Tables[0]);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);
}
}
private Employees GetData(string query)
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlCommand cmd = new SqlCommand(query);
cmd.CommandType = CommandType.StoredProcedure;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (Employees dsEmployees = new Employees())
{
sda.Fill(dsEmployees, "DataTable1");
return dsEmployees;
}
}
}
}
Screenshot
Refer the below article how to use report viewer in asp.net.