skip to the main content area of this page
Patterns and Practices

RealTimeSearchMonitor Control for Live GridView Filtering and Searching in ASP.NET


The Search Bundle in WCSF v2.0 offers a RealTimeSearchMonitor Control to help implement real-time searching and filtering in ASP.NET. You can learn about it more from the following screencast and tutorial:

I am using the RealTimeSearchMonitor Control in various places on PnPGuidance. One such place is in the area to view and edit previous posts:

 

RealTimeSearchMonitor Control

 

Here is a screenshot of the design-time experience showing the RealTimeSearchMonitor Control on the form:

 

RealTimeSearchMonitor Control

 

The RealTimeSearchMonitor Control monitors the txtTitleFilter TextBox for changes, and if a change occurs, fires an asynchronous postback to the UpdatePanel based on the TextBox's TextChanged Event. Here are the settings:

 

<cc1:RealTimeSearchMonitor
        ID="RealTimeSearchMonitor1"
        AssociatedUpdatePanelID="UpdatePanel1"
        Interval="700"
        runat="server">
            <ControlsToMonitor>
                <cc1:ControlMonitorParameter TargetID="txtTitleFilter" />
            </ControlsToMonitor>
</cc1:RealTimeSearchMonitor>

 

You need to handle the txtTitleFilter_TextChanged Event on the web server and pass the event to the Presenter Class using Model-View-Presenter.

 

void txtTitleFilter_TextChanged(object sender, EventArgs e)

{

    _presenter.OnGetPosts();

}

 

The Presenter will get the value of the filter via the View Interface Contract ( View.Filter shown below ) and pass the request to the BlogService in this case:

 

public void OnGetPosts()

{

    int totalRows;

    View.Posts = _blogService.GetPosts(View.StartRow,

        View.MaxRows, View.Filter, View.SortExpression, out totalRows);

    View.TotalRows = totalRows;

}

 

The View has a Filter Property of type string that provides the value typed into the txtTitleFilter TextBox:

 

public string Filter

{

    get { return txtTitleFilter.Text; }

}

 

Here is the Interface for the View which allows for filtering, sorting, and paging of the data in the GridView:

 

public interface IViewPostsView

{

    string Filter { get; }

    int StartRow { get; }

    int MaxRows { get; }

    string SortExpression { get; }

 

    IList Posts { set; }

    int TotalRows { set; }

}

 

You can read more about the server-side paging of the GridView using the ObjectContainerDataSource in the following post:


Tags: ModelViewPresenter, RealTimeSearchMonitor, SearchBundle


Topics



Popular Tags



Recent Links