c# - 如何根据条件更改 RDLC 报告中文本框的文本?
问题描述
我有一份RDLC
报告。该报告中有一个显示文本,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
inReport .rdlc Design
和Drag and Drop
paramHeader
into 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
等等..
推荐阅读
- vba - 以自定义尺寸打印 Microsoft Access PDF 报告
- r - 如何提高返回对齐序列坐标的 R 函数的性能?
- notepad++ - 查找并删除重复的术语?
- cassandra - 使用 cassandra-stress 工具插入特定数据,而不是随机的
- c# - 我想同时运行 3 个方法,其他方法等到任何方法完成
- tensorflow - 使用 Tensorflow saved_model,得到 ValueError: Cannot feed value of shape () for Tensor 'Placeholder_1084:0', which has shape '(?,)'
- html - 如何修复位置为粘性的块的覆盖
- .net - 登录iTextSharp时如何自动输入密码
- flutter - FCM 从主题退订特定令牌
- laravel - 编辑表单时未获取动态依赖列表值