MS ReportViewer in ASP.Net, how to pass parameter values
In my ASP.Net
project, I have added a data report and connected with Dataset.
It works fine but I have two issues:
1) I want to load the report after a button on the page carrying MSReportViwer is pressed, say it is Show Report button. At the moment report is loading just at form load.
2) I wan开发者_JS百科t to pass some parameter values to the sql query generating the report.
For example
Where Name=@NM and City=@CT
values of NM
and CT
shall be given in the text boxes on the same form. After this i press the button 'Show Report'
and it should display the report.
Please advise how to do it. Thanks
Create a button and place it on the form. Double clicking it will create a click event:
private void button_Click(object sender, EventArgs e)
{
this.thenameofyourtableadapter.Fill(this.yourdataset.thenameofyourdatatable);
this.thenameofyourreportviewer.RefreshReport();
}
Move the tableadapter/dataset Fill line of code to inside this event (as seen above).
As for the passing of a parameter to the dataset:
Go to the Datset itself and find the Tableadapter that populates your Datatable. If you want to change the query you are currently using to include parameters, click configure on the current query as seen here.
The new query would resemble something like: select * from customers where Name=@NM and City=@CT .
You need to then go back to the code above where you were filling your tableadapter (in the button press) and change it to snag the parameters from your other controls, such as a text box:
private void button_Click(object sender, EventArgs e)
{
this.thenameofyourtableadapter.Fill(this.yourdataset.thenameofyourdatatable,Textbox1.Text,Textbox2.Text);
this.thenameofyourreportviewer.RefreshReport();
}
This would cause your report to only display results based on the parameters you feed it.
精彩评论