SIGN UP MEMBER LOGIN:    
ARTICLE

Implementing Search in Reports using ReportViewer

Posted by Mahesh Chand Articles | Reports using C# April 30, 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.
Reader Level:
Download Files:
 

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.



Figure 1.

I definite the following variable in the class:

private bool firstFound = false;

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

private void FindButton_Click(object sender, EventArgs e)

{

     if (firstFound)

         this.reportViewer1.FindNext();

     else if (this.reportViewer1.Find(FindTextBox.Text, 1) >= 0)

         firstFound = true;

}

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.

 

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.

Login to add your contents and source code to this article
share this article :
post comment
 

I want to do Hindi Search from database

Posted by Rajkumar Mishra Jun 05, 2010

thank you! I'll take a look.

Posted by Hai Bui Thanh Mar 28, 2010

if u have any code related to this, pls upload ur side. i already tried lot but doesnt get. even i build the code as myself using some available resources,but not find. above code there is some problem like when i put something at second time it is unable to find.

Posted by alok pandey Jan 06, 2009

First Time it search if i put different search in the textBox it is unable to find that Please Correct It

Posted by vikas vyas Dec 25, 2007
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • 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!
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Team Foundation Server Hosting
Become a Sponsor