I have a web form where I have a textbox in which the user will enter the number and pull the information from the table. Now I have developed a xtrareport, where I have to display the data of which the user enters in that textbox which I mentioned earlier. Everythin开发者_运维问答g works fine, only I need to just pass the value of the texbox(form1) to the report (form2).
Now what I need is how to pass the textbox value as a parameter to the report and display the report data of the selected number.
- In the Report Designer You should create Report Parameter and use it anywhere in report(for example in report filter).
- Before showing report to user you should find parameter in report instance and assign value to it.
here is sample code:
using (var report = new XtraReport())
{
report.Bands.Add(new DetailBand());
report.Parameters.Add(new Parameter { Name = "userName",ParameterType = ParameterType.String});
report.FilterString = "USER = userName";
report.SaveLayout("test.repx");
}
using (var report = new XtraReport())
{
report.LoadLayout("test.repx");
report.Parameters.First(p => p.Name == "userName").Value = textBox.Text;
report.ShowPreviewDialog();
}
Notice
It is winform sample. But principles are same. Also it is very simple to pass textbox value to webform via querystring for example.
Get that textedit value and pass through constructor.
string oper = "A";
XtraReport_1 report = new XtraReport_1(oper, Convert.ToInt32(TextEdit1.Text));
ReportPrintTool tool = new ReportPrintTool(report);
tool.ShowPreview();
Write this code in event that where fires report.
In XtraReport_1
get that constructor and use it.
public InvoiceReport_1(string oper, int p)
{
// TODO: Complete member initialization
InitializeComponent();
InvisibleText.Text = p.ToString();
InvisibleText.Visible = false;
getOper = oper;
}
now you get the value to TextEdit calld "InvisibleText".
精彩评论