Skip to main content

Cloud

Quick custom Search Results web part

To create a search results web part that will dynamically create a search query and render the search results is pretty easy.

Create a new web part and inherit the CoreResultsWebPart.

public class MySearchWebPart: CoreResultsWebPart
{
     public MySearchWebPart(): base()
     {
          // Initialize the search results web part here…
         //e.g this.ResultsPerPage = 10;
         //Set the Fixed Query here.
         this.FixedQuery = “Some Query”; // Build query based on some criteria. Either from Page Fields, keywords, etc.
      }
}

.ExternalClassD5F93078116B4883B34A7A2CB705C28A .csharpcode, .ExternalClassD5F93078116B4883B34A7A2CB705C28A .csharpcode pre
{font-size:small;color:black;font-family:consolas, "Courier New", courier, monospace;background-color:#ffffff;}
.ExternalClassD5F93078116B4883B34A7A2CB705C28A .csharpcode pre
{margin:0em;}
.ExternalClassD5F93078116B4883B34A7A2CB705C28A .csharpcode .rem
{color:#008000;}
.ExternalClassD5F93078116B4883B34A7A2CB705C28A .csharpcode .kwrd
{color:#0000ff;}
.ExternalClassD5F93078116B4883B34A7A2CB705C28A .csharpcode .str
{color:#006080;}
.ExternalClassD5F93078116B4883B34A7A2CB705C28A .csharpcode .op
{color:#0000c0;}
.ExternalClassD5F93078116B4883B34A7A2CB705C28A .csharpcode .preproc
{color:#cc6633;}
.ExternalClassD5F93078116B4883B34A7A2CB705C28A .csharpcode .asp
{background-color:#ffff00;}
.ExternalClassD5F93078116B4883B34A7A2CB705C28A .csharpcode .html
{color:#800000;}
.ExternalClassD5F93078116B4883B34A7A2CB705C28A .csharpcode .attr
{color:#ff0000;}
.ExternalClassD5F93078116B4883B34A7A2CB705C28A .csharpcode .alt
{background-color:#f4f4f4;width:100%;margin:0em;}
.ExternalClassD5F93078116B4883B34A7A2CB705C28A .csharpcode .lnum
{color:#606060;}

That’s it. This will give you fresh content based on the query that is built at runtime.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Amol Ajgaonkar

More from this Author

Follow Us