ARTICLE

Implementing Search in Reports using ReportViewer

Posted by Mahesh Chand Articles | Reports in VB.NET May 09, 2007
The ReportViewer control provides Find and FindNext methods to find a text in the report. This article explains how you can implement search functionality in reports programmatically.
Download Files:
 
Reader Level:

The ReportViewer control provides Find and FindNext methods to find a text in the report. The Find method takes two parameters - the text and the starting page number.

Now let's create a Windows Forms application and add a TextBox and a Button control to the form. The button click would search the text entered in the TextBox.

I have Form with a TextBox and a Button control. See Figure 1.

SearchReportImg.jpg

Figure 1.

I definite the following variable in the class:

Private firstFound As Boolean = False

The following code written on the Find Button click event handler.

Private Sub FindButton_Click(ByVal sender As Object, ByVal e As EventArgs)

    If firstFound Then

        Me.reportViewer1.FindNext()

    Else

        If Me.reportViewer1.Find(FindTextBox.Text, 1) >= 0 Then

            firstFound = True

        End If

    End If

End Sub

Now if I type "Chand" in the TextBox and click the Find button, the first row is selected. Clicking Find again select the next row that has text Chand in it. See Figure 2.

SearchReportImg2.gif

Figure 2.

Download the attached project to see more details and working code.

To learn more about how to generate reports from database, XML documents, and objects, check my articles published in SQL Reporting Services section of this site.

share this article :
post comment
 

Interesting. I did not know that. You may want to post your question on forums.

Good luck!

Posted by Mahesh Chand Apr 07, 2009

Hi, Find and FindNext methods do not exist in WebForms ReportViewer. How can I implement Find and FindNext using WebForms ReportViewer? Thanks

Posted by Elisabeth Dec 01, 2008
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor