我想用参数的“文本框和按钮”Ex显示“ReportView”。像搜索按钮一样。你能给我一些代码示例。
提前感谢。
答案 0 :(得分:1)
希望您使用的是asp.net WebForms,
下面的代码(C#)从文本框中获取一个值并将其显示在 报告。
reportViewer1.LocalReport.ReportEmbeddedResource = "path_to_the_embedded_report";
ReportParameter[] parameters = new ReportParameter[1];
parameters[0] = new ReportParameter("ReportParam1", textbox1.Text, true);
reportViewer1.LocalReport.SetParameters(parameters);
reportViewer1.RefreshReport();
您可能需要解析一些引用,并通过NuGet将报表查看器添加到您的项目中。
希望有所帮助。
答案 1 :(得分:0)
对不起,我无法评论你的问题。如果使用服务器报告Microsoft,则可以使用RDL文件。您可以添加有关ReportProgramm的信息吗?
string[] parameter = = new string[3] {"1","2","3" };//here you can change to your TextBox
//This is optional if you have parameter then you can add parameters as much as you want
Microsoft.Reporting.WebForms.ReportParameter[] param = new Microsoft.Reporting.WebForms.ReportParameter[3];
param[0] = new Microsoft.Reporting.WebForms.ReportParameter("firstParam", parameter[0], true);
param[1] = new Microsoft.Reporting.WebForms.ReportParameter("SecondParam", parameter[1], true);
param[2] = new Microsoft.Reporting.WebForms.ReportParameter("thirdParam", parameter[2], true);
Microsoft.Reporting.WebForms.ReportViewer report = new Microsoft.Reporting.WebForms.ReportViewer();
report.ServerReport.ReportServerCredentials = new CustomReportCredentials("Name", "Password", "DomName");
report.ServerReport.ReportServerUrl = new Uri("yourPathtoserver");// Report Server URL
report.ServerReport.ReportPath = "reportpathWithHimName";// Report Name with path!
report.ServerReport.SetParameters(param);
report.ServerReport.Refresh();
对不起,如果我没有回答你的问题。
public class CustomReportCredentials : IReportServerCredentials
{
private string _UserName;
private string _PassWord;
private string _DomainName;
public CustomReportCredentials(string UserName, string PassWord, string DomainName)
{
_UserName = UserName;
_PassWord = PassWord;
_DomainName = DomainName;
}
public System.Security.Principal.WindowsIdentity ImpersonationUser
{
get { return null; }
}
public ICredentials NetworkCredentials
{
get { return new NetworkCredential(_UserName, _PassWord, _DomainName); }
}
public bool GetFormsCredentials(out Cookie authCookie, out string user,
out string password, out string authority)
{
authCookie = null;
user = password = authority = null;
return false;
}
}