Microsoft.Reporting.WebFormsClient.ReportViewer.find Method

Searches the report for the specified text string.

$find(viewerId).find(text);

Parameters

  • Text
    The string to search for.

Remarks

This method starts the search from the report page that is currently displayed in the report area and highlights the first search hit. The corresponding server-side method is Find.

When the Web page is performing a postback or the client-side control is loading content, accessing the methods or properties will cause an exception with the message: "The report or page is being updated. Please wait for the current action to complete." Use the isLoading property to check whether the report or page is being updated and whether you can access the methods and properties.

When the Web page or the client-side control is not performing a postback, this method requires that a report is loaded. If no report is loaded, invoking this method will cause an exception with the message: "The operation cannot be performed because there is no report loaded." Use the reportAreaContentType property to check whether the report area contains a report page before you use this method.

The following ASP.NET page uses an external text box and two external buttons to search the report for a string.

<%@ Page Language="C#" %>

<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Path="Find.js" />
        </Scripts>
    </asp:ScriptManager>
    <rsweb:ReportViewer ID="ReportViewer1" runat="server" ProcessingMode="Remote" >
        <ServerReport ReportPath=" /AdventureWorks 2008 Sample Reports/Product Catalog 2008" 
            ReportServerUrl="http://<myserver>/reportserver" />
    </rsweb:ReportViewer>
    <asp:TextBox ID="SearchString" runat="server"></asp:TextBox>
    <asp:Button ID="FindButton" runat="server" Text="Find" OnClientClick="return findString($get('SearchString').value);" />
    <asp:Button ID="NextButton" runat="server" Text="FindNext" OnClientClick="return nextHit();" />
    </form>
</body>
</html>

The code for Find.js, referenced by the ASP.NET page, is provided below.

function findString(str) {
    var viewer = $find("ReportViewer1");
    if (!viewer.get_isLoading() && viewer.get_reportAreaContentType() ==
    Microsoft.Reporting.WebFormsClient.ReportAreaContent.ReportPage) {
        viewer.find(str);
    }
    return false;
}

function nextHit() {
    var viewer = $find("ReportViewer1");
    if (!viewer.get_isLoading() && viewer.get_reportAreaContentType() ==
    Microsoft.Reporting.WebFormsClient.ReportAreaContent.ReportPage) {
        viewer.findNext();
    }
    return false;
}

See Also

Reference

Microsoft.Reporting.WebFormsClient.ReportViewer Class
Microsoft.Reporting.WebFormsClient.ReportViewer.findNext Method