我有一个RDLC
报告。该报告中有一个名为TextBox
的{{1}},它显示诸如TextBox2
之类的文本。现在,我想根据某些条件更改该文本框的文本。就像当我单击All Employees Record
按钮时,Hired Employees
的文本应更改为“雇用员工记录”而不是TextBox2
,而当我单击All Employees Record
按钮时, Rejected Employees
的文本应更改为“拒绝员工记录”。这是我要发送的报告页面的加载事件的条件
TextBox2
当第二个条件返回true时,texbox文本更改为 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
}
}
}
,依此类推....
我的第二个问题是,在报告中,只有第一页具有标题文本,其余页面没有标题文本。如何实现呢?请帮助我。
答案 0 :(得分:0)
几天前我在这里问了一个问题,但我还没有答案。因此,我继续搜索并解决了我的问题。因此,我想为此提供一个答案,希望如果有人卡在这里,那么有人会从我的答案中获得帮助。毕竟我们必须互相帮助。 所以一步一步来。
1)我通过右键单击从-ffixed-r10
工具箱中添加了r10
,并添加了参数并将其命名为Parameter
。
2)我在Report Data
中添加了paramHeader
,并在Textbox
中添加了Report .rdlc Design
Drag and Drop
。
3)然后,在我的paramHeader
方法中添加以下Textbox
代码。
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
中显示的字符串Value
所以我的整体方法看起来像这样
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
应该显示{{1 }}等等..