Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I would like to display my search results in a table-like fashion. Does anyone know any good technique that I can use to display my custom columns in a table fashion?

I used a html table, but it keeps repeating even though I used this:

<xsl:if test="(position())=1">

<tr>
<td>Address</td>
</tr>
</xsl:if>
<tr>
<td>content goes here</td>
</td>

It is still adding spaces between each row and it looks like separate tables. I would like it to look like a gridview, or like the one in a list or library.

Thank you for your help.

share|improve this question

2 Answers 2

XSLT: PS : https://sharepoint2010search.codeplex.com/releases/view/48888 OR

You can create a custom webpart and display results in a grid view or spgridview which will provide options of grouping,filtering,paging etc . PS: http://sharepointcafe.net/Forum/131-SharePoint-search-result-display-in-a-Gridview

    protected override void Render(HtmlTextWriter writer)
    {
        string currUser = SPContext.Current.Web.CurrentUser.Name;
        string searchQuery = "select title, sitetitle,path from scope()";
        FullTextSqlQuery query = new FullTextSqlQuery(SPContext.Current.Site);

        query.ResultTypes = ResultType.RelevantResults;
        query.QueryText = searchQuery;
        ResultTableCollection result = query.Execute();

        ResultTable resultTable = result[ResultType.RelevantResults];
        DataTable dt = new DataTable();
        dt.Load(resultTable, LoadOption.OverwriteChanges);

        SPGridView spGrid = new SPGridView();
        spGrid.AutoGenerateColumns = false;

        foreach (DataColumn dColumn in dt.Columns)
        {
            SPBoundField field = new SPBoundField();
            field.HeaderText = dColumn.ColumnName;
            field.DataField = dColumn.ColumnName;
            spGrid.Columns.Add(field);
        }

        spGrid.DataSource = dt;
        spGrid.DataBind();

        Controls.Add(spGrid);
        spGrid.RenderControl(writer);
        //base.Render(writer);
    }
share|improve this answer

It is certainly possible, however it would require to understand a little bit how the results are returned and then change the XSLT appropiately. I would suggest strongly to go through collecting the actual XML and use SharePoint Designer 2010 to change the output any way you see fit.

Basically you would need to collect the XML and add it a Data Source in SharePoint designer. Use this XSLT in your Core Search REsults web part to collect the actual output, before the XSLT transformation of the rendering.

<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 
<xsl:template match="/"> 
  <xmp><xsl:copy-of select="*"/></xmp> 
</xsl:template> 
</xsl:stylesheet>

Tobias Zimmerman has a series of articles, which is still viable for SharePoint 2010. Find it here http://zimmergren.net/technical/moss-2007-customize-the-search-result-using-xslt-part-3-customize-using-sharepoint-designer-2007

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.