Customizing Layout (Template Usage)

Total control over the appearance of the search results is provided through the template mechanism. SearchResult is a templated control, similar to "DataGrid" or "Repeater", it has a set of templates which can be defined to control layout and style.

HeaderTemplate

The block of Html before the search results can be defined in the header template, it's properties, which are accessed in standard fashion;

<%# Container.QueryExpression %>

NextPageLink
Link to the next page of results to be shown, typical usage is:
<%# Container.NextPageLink %>
Which will result in an anchor tag being shown on the page if not currently showing last page of results.

PreviousPageLink
As above, except for the previous page of results unless on first page.

NumberOfResults
The number of results found.

NumberOfResultsPerPage
The number of results per page, typically used in calculations, eg:
Showing results <%# ((Container.ResultsPage - 1)* Container.NumberOfResultsPerPage + 1) %> to <%# ((Container.ResultsPage - 1)* Container.NumberOfResultsPerPage) + Container.ResultsOnPage%>

QueryExpression
The expression that was search for.

ResultsOnPage
The number of results on the current page.

ResultsPage
The current page of results being shown.

IgnoredWordsMessage
The common words that were ignored.

FooterTemplate

The block of Html after the search results;

NextPageLink
Link to the next page of results to be shown, typical usage is: <%# Container.NextPageLink %> which will result in an anchor tag being shown on the page if not currently showing last page of results.

PreviousPageLink
As above, except for the previous page of results unless on first page.

NumberOfResults
The number of results found.

NumberOfResultsPerPage
The number of results per page, typically used in calculations, eg:
Showing results <%# ((Container.ResultsPage - 1)* Container.NumberOfResultsPerPage + 1) %> to <%# ((Container.ResultsPage - 1)* Container.NumberOfResultsPerPage) + Container.ResultsOnPage%>

QueryExpression
The expression that was search for.

ResultsPage
The current page of results being shown.

PageLinksBlock
A block of page number links, enabling the user to move directly to a result page.

ResultItemTemplate

Repeated for each result found, this is where the layout of the results can be defined.

Summary
The summary of the result document.

Title
The title of the result document.

Uri
The Uri/URL of the result document.

ResultPreview_Expander_ClosedUrl, ResultPreview_Expander_OpenedUrl, and UriAsStored
Used by the result previewer client side code, which is part of the default template.

CustomData
See the 'How To Work With Custom Data' section of the Help documentation.

NoResultsTemplate

Shown alone when there were no results found.

QueryExpression
The expression that was searched for.

IgnoredWordsMessage
The common words that were ignored.

ErrorMessageTemplate

Shown when there was a search error (from invalid user input).

Message
User friendly error message.

ExceptionMessage
The actual exception that occurred.

NoQueryTemplate

Shown alone when there was no QueryExpression.

SearchBox
Displayed when the page containing the SearchResult control is accessed directly without a search query.

Example From "Example2_CustomLayout"

...
<searchengine:searchresult id="SearchResult1" runat="server" HighlightQueryWordsInSummary="False" Width="915px"
    IndexDirectory="C:\inetpub\wwwroot\KeyotiSearchDemo_CSharp\IndexDirectory" SummaryWordLength="100">

    <ResultItemTemplate>
        <A href="<%# Container.Uri %>">
            <div onmouseover="highlight(this)" onmouseout="unhighlight(this)" class='SEResultItem'
                style="cursor: hand;" style='font-family: sans-serif,
Verdana, Arial, Helvetica; font-size:9pt; background-color:#E4FCE4; borderleft:
3px solid #15BD15;padding:6px;border-bottom:1px solid
#15BD15;padding:6px;'>
                <span class='SEResultItemLink' style='font-family:sansserif,
Verdana, Arial, Helvetica; font-size:11pt; font-weight:bold; '>
                    <%# Container.Title %>
                </span>
                <br>
                <span class='SEResultItemURL' style='font-family:sansserif,
Verdana, Arial, Helvetica; font-size:8pt; color: blue; paddingleft:
14px;'>
                    <%# Container.Uri %>
                </span>
                <br>
                <span class='SEResultItemSummary' style='fontfamily:
sans-serif, Verdana, Arial, Helvetica; font-size:10pt;margin-left:14px;'>
                    <%# Container.Summary%>
                </span>
                <br>
            </div>
        </A>
    </ResultItemTemplate>
   
    <HeaderTemplate>
        <div class='SEHeader' style='font-family: sans-serif, Verdana, Arial, Helvetica; font-size:12pt; background-color:#C2F8C2; border-top: 1px solid
#15BD15; border-left:3px solid #15BD15;border-right: 1px solid #15BD15;
padding:6px;border-bottom:1px solid #15BD15;padding:6px;'>
            You searched for '<%# Container.QueryExpression %>', there are
            <%# Container.NumberOfResults %>
            results. Showing results <%# ((Container.ResultsPage - 1)*
Container.NumberOfResultsPerPage + 1) %> to
            <%# ((Container.ResultsPage - 1)*
Container.NumberOfResultsPerPage) + Container.ResultsOnPage%>
        </div>
    </HeaderTemplate>

    <FooterTemplate>
        <div class='SEFooter' style='font-family: sans-serif, Verdana, Arial,
Helvetica; font-size:9pt; background-color:#C2F8C2; border-left:3px solid
#15BD15;border-right: 1px solid #15BD15; padding:6px;border-bottom:1px solid
#15BD15;padding:6px;'>
            <table border="0" cellpadding="0" cellspacing="3">
                <tr>
                    <td style='font-family: sans-serif, Verdana, Arial,
Helvetica; font-size:9pt;'>Results
                            Page:
                    </td>
                    <td style='font-family: sans-serif, Verdana, Arial,
Helvetica; font-size:9pt;'><%# Container.PreviousPageLink %></td>
                    <td style='font-family: sans-serif, Verdana, Arial,
Helvetica; font-size:9pt;'><%# Container.PageLinksBlock %></td>
                    <td style='font-family: sans-serif, Verdana, Arial,
Helvetica; font-size:9pt;'><%# Container.NextPageLink %></td>
                </tr>
            </table>
        </div>
    </FooterTemplate>

    <NoResultsTemplate>
        <div class='SENoResults' style='font-family: sans-serif, Verdana,
Arial, Helvetica; font-size:9pt; padding:4px;'>Sorry, no results were found for the query "<%#
Container.QueryExpression %>".</div>
    </NoResultsTemplate>

</searchengine:searchresult>

In this example the default error message will be used, as it has not been specified.