Hi Folks,
I've been trying since a long time finding an article of how to pass parameters to a Report Viewer control in Visual Studio 2010, but most of the articles needs lots of code to be written.
But, now I have found the way to create a report and pass parameters easily with only 1 line of code, yes I am serious 1 line of code!! :)
And below I will describe the steps with screen shots:
1- You need to create a new Visual Studio Web Site:
2- Then you will have an empty web site.
3- Now, I will create a new database with one table with three columns (ID, Name, City):
Then fill it with some data:
Now I will create a data set for the Contacts table:
Now I will Rebuild the web site:
Now, we need to add reference to Microsoft.ReportViewer.WebForms:
Make sure to select Version 10.0.0.0
Now, I will create a report:
Save the report.
Now, I will start to build the page of the report:
- Add a DropdownList and a Button:
- Drop a Script Manager control into the page:
- Drop a ReportViewer control:
- Choose the Report we created before, and an ObjectDataSource will be created directly:
- On the Click event of the button write the only Code you need to write to refresh the report:
ReportViewer1.LocalReport.Refresh()
Congratulations!! the web site is ready and the report takes the parameter and refreshes.
Happy programming!
Saed
I've been trying since a long time finding an article of how to pass parameters to a Report Viewer control in Visual Studio 2010, but most of the articles needs lots of code to be written.
But, now I have found the way to create a report and pass parameters easily with only 1 line of code, yes I am serious 1 line of code!! :)
And below I will describe the steps with screen shots:
1- You need to create a new Visual Studio Web Site:
2- Then you will have an empty web site.
3- Now, I will create a new database with one table with three columns (ID, Name, City):
Then fill it with some data:
Now I will create a data set for the Contacts table:
Now I will Rebuild the web site:
Now, we need to add reference to Microsoft.ReportViewer.WebForms:
Make sure to select Version 10.0.0.0
Now, I will create a report:
Save the report.
Now, I will start to build the page of the report:
- Add a DropdownList and a Button:
- Drop a Script Manager control into the page:
- Drop a ReportViewer control:
- Choose the Report we created before, and an ObjectDataSource will be created directly:
- On the Click event of the button write the only Code you need to write to refresh the report:
ReportViewer1.LocalReport.Refresh()
Congratulations!! the web site is ready and the report takes the parameter and refreshes.
Happy programming!
Saed
Nice article, helped me a lot, Thanks
ReplyDeleteThis was a great sample, thanks for sharing.
ReplyDeleteHow can I get the dropdown to fill with values from a data field instead of what I put in the list items?
Excellent! Saved me lots of time on my project. Keep posting
ReplyDeleteThanks I've been looking for hours for something like this! I filled the dropdown with values from a table by adding an SQL datasource, configuring it to get the values I wanted then binding the Datasource to the DropDown list. Also instead of using a button you can just enable Postback on the DropDownlist and add the refresh code to the SelectedIndexChanged event of the Dropdown. I also added an all record option to the dropdown.
ReplyDeleteThank you for posting this. Helped me a lot.
ReplyDeleteyou are the greatest!!! you dont no how much you have helped me man!!! i will always follow your blog!!!
ReplyDeleteMan, thank you so much, so much. Helped me a lot. Thank you very much for this tutorial, nothing else better than this. Muito Obrigado, Ivan, Brazil.
ReplyDeleteExcellent, Thanks for sharing
ReplyDeleteThanks very much! I searched for quite awhile for this parameter part!!!
ReplyDeletethank you very much...
ReplyDeleteit help me direct UI is great way...man
I am happy it helped you guys ...
ReplyDeletePlease note that I have moved this blog to: saedshaar.com
Happy programming!
Saed
We have done everything, but report is not showing anything after selecting the paramter
ReplyDelete