我有一个RDLC
Report。有在报告中显示像TextBox
文本名为TextBox2
一个All Employees Record
。现在我想改变一些条件的基础上,该文本框的文本。就像当我点击然后Hired Employees
按钮TextBox2
的文本应改为而不是All Employees Record
“聘用的员工记录”,当我在Rejected Employees
按钮点击,那么TextBox2
的文本应改为“被拒绝的员工记录”。下面是报告页面我发送的负载情况下的条件
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (EmployeeID.PrintAllEmployees == "ALL EMPLOYEES")
{
PrintAllEmployeesMethod();
}
else if (EmployeeID.PrintAllEmployees == "HIRED EMPLOYEES")
{
PrintHiredEmployeesMethod();
}
else if (EmployeeID.PrintAllEmployees == "REJECTED EMPLOYEES")
{
PrintRejectedEmployeesMethod();
}
else if (EmployeeID.PrintAllEmployees == "UNVERIFIED EMPLOYEES")
{
PrintUnverifiedEmployeesMethod();
}
else
{
//SOMETHING
}
}
}
当第二个条件返回true,则texbox文本改为Hired Employees Record
等等....
我的第二个问题是,在报告中,仅在第一页有头文本,其余页面显示没有标题的文本。如何实现这一目标?请帮我。
我问了问这里的天夫妇之前,但我还没有得到答案。所以我一直寻找和解决我的问题。所以,我想提出一个答案,在希望,如果有人来到这里停留,然后有人从我的回答帮助。毕竟我们要互相帮助。所以一步一步。
1)我通过点击鼠标右键加到从Parameter
工具箱Report Data
并添加参数,并把它命名为paramHeader
。
2)我加入Textbox
一个Report .rdlc Design
,并Drag and Drop
paramHeader
到Textbox
。
3)然后我加入我的C#
方法如下PrintReport
代码。
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Reports/rptAllEmployeeRecord.rdlc");
//Passing Parameter
ReportParameterCollection reportParameters = new ReportParameterCollection();
reportParameters.Add(new ReportParameter("paramHeader", "HIRED EMPLOYEES REPORT"));
this.ReportViewer1.LocalReport.SetParameters(reportParameters);
在这里,ParamHeader
是我在第一步中添加参数名称和HIRED EMPLOYEES REPORT
是,我想在我的第二个步骤中添加的TextBox
显示的字符串值。
因此,我的总体方法看起来像这样
public void PrintHiredEmployeesMethod()
{
//set Processing Mode of Report as Local
ReportViewer1.ProcessingMode = ProcessingMode.Local;
//set path of the Local report
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Reports/rptAllEmployeeRecord.rdlc");
//Passing Parameter
ReportParameterCollection reportParameters = new ReportParameterCollection();
reportParameters.Add(new ReportParameter("paramHeader", "HIRED EMPLOYEES REPORT"));
this.ReportViewer1.LocalReport.SetParameters(reportParameters);
//creating object of DataSet dsEmployee and filling the DataSet using SQLDataAdapter
DataSetAllEmployee dsemp = new DataSetAllEmployee();
using (SqlConnection con = new SqlConnection(Base.GetConnection))
{
SqlCommand cmd = new SqlCommand(@"SELECT * FROM TableEmployee WHERE Status=@Status", con);
cmd.CommandType = System.Data.CommandType.Text;
cmd.Parameters.AddWithValue("@Status","HIRED");
con.Open();
SqlDataAdapter adapt = new SqlDataAdapter(cmd);
adapt.Fill(dsemp, "dtAllEmployeeRecord");
}
//Providing DataSource for the Report
ReportDataSource rds = new ReportDataSource("DataSetAllEmployee", dsemp.Tables[0]);
ReportViewer1.LocalReport.DataSources.Clear();
//Add ReportDataSource
ReportViewer1.LocalReport.DataSources.Add(rds);
}
我Page_Load
事件看起来是这样
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (EmployeeID.PrintAllEmployees == "ALL EMPLOYEES")
{
PrintAllEmployeesMethod();
}
else if (EmployeeID.PrintAllEmployees == "HIRED EMPLOYEES")
{
PrintHiredEmployeesMethod();
}
else if (EmployeeID.PrintAllEmployees == "REJECTED EMPLOYEES")
{
PrintRejectedEmployeesMethod();
}
else if (EmployeeID.PrintAllEmployees == "UNVERIFIED EMPLOYEES")
{
PrintUnverifiedEmployeesMethod();
}
else
{
//SOMETHING
}
}
}
请注意,我有四个不同的方法,但我根据我的需要改变Header
科。就像当一个用户要打印HIRED EMPLOYEES REPORT
,然后Header Section
显示HIRED EMPLOYEES REPORT
,如果用户想生成ALL EMPLOYEES REPORT
,则宜Header Section
显示ALL EMPLOYEES REPORT
等..