Search API form - display to a DataGrid
[This is C# version] [VB
findinsite-ms has a
Search API web service - a programmer interface to the search engine
that can be used over the internet.
This ASP.NET example shows a search form and displays the results in a DataDrid
control, displaying 10 hits at a time. This approach is familiar as this is how
most search engines display their results - although the layout could be
If you do a search for * here (ie to find all possible hits) then the
page should return quickly because only 10 results have to be returned to your
browser. The same search done in Example 1
could take a long time over a slow connection because hundreds of results have
to be returned. However, see the Information
Flows section for a full discussion of possible delays.
The results are cached in a Session variable so that requests for another set
of hits can be fulfilled without having to call the Search API.
Try out the search form - then see below for programming
The example works in exactly the same way as
Example 1 so full programming details are not shown.
methods are largely the same. However
the DataGrid page index to zero, and stores the result in the "fisSearchResult"
HitDataGrid.CurrentPageIndex = 0;
Session["fisSearchResult"] = result;
HitDataGrid DataGrid control is used in a very similar way to
the Repeater control in example 1, ie the
array is set as its DataSource. The DataGrid control PageIndexChanged event is
set to the new script method
private void Page_Change(object source, DataGridPageChangedEventArgs e)
// Set CurrentPageIndex to the page the user clicked.
HitDataGrid.CurrentPageIndex = e.NewPageIndex;
fisClient.fisSearchResult result = (fisClient.fisSearchResult)Session["fisSearchResult"];
result = new fisClient.fisSearchResult();
result.Message = "Session did not store fisSearchResult";
catch( Exception ex)
This code sets the DataGrid control CurrentPageIndex, retrieves the result from
the Session variable, and calls
ShowResults() as before.
The example can be enhanced easily to cope if the Session has expired.