Click here to Skip to main content
15,886,019 members
Articles / All Topics

How to Customize SharePoint List Content Display using Content Query Web Part

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
21 Dec 2011CPOL2 min read 27K   4   2
How to use Content Query Web Part to Style SharePoint List

Here, I'm going to describe how we can use Content Query Web Part to Style SharePoint List. Thus, assume we are having a SharePoint List called Projects with the following fields.

image

As you already knew, the default look and feel would be like below:

image

Now I'm going to render this list in to format something like below:

image

Step One

First, you need to define some names for these place holders (yeh, I know this do not make any sense to you. But don’t worry, just do the step). Thus, I'm going to define these columns as follows:

  • Title –> MyTitle
  • Logo –> MyLogo
  • Project Summary –> MySummary
  • Project Description –> MyDesc

Step Two

Now you want to define an XSL Style Sheet using these names. Therefore, I'm going to use <table> to layout the list item as below:

XML
<xsl:template name="MyStyle" 
match="Row[@Style='MyStyle']" mode="itemstyle">

<table border='1'>
    <tr>
        <td colspan="2"><h3>
        <xsl:value-of select="@MyTitle" /></h3></td>
    </tr>
    <tr>
        <td>
            <img>
            <xsl:attribute name="src">
                <xsl:value-of select="@MyLogo" />
            </xsl:attribute>
            </img>
        </td>
        <td>
            <xsl:value-of disable-output-escaping="yes" 
            select="@MySummary" />
         </td>
    </tr>
    <tr>
        <td colspan="2">
            <xsl:value-of disable-output-escaping="yes" 
            select="@MyDesc" />
        </td>
    </tr>
    </table>
 
</xsl:template>

Here, I used XSLT to position the content inside my HTML tags. There are few attributes which are mandatory in this section.

  • Name and match should have equal names.
    • name =’X’ match=Row[@style=’X’]
  • mode = ‘itemstyle

Now you have created XSLT which can be given as a list style in the SharePoint.

Step Three

Here, we are going to put XSLT to the SharePoint.

First, you need to open the SharePoint designer with the particular site. Then, navigate to All Files and Style Library.

Image 4

Here, you can see many folders inside. Now you have to go to XSL Style Sheet Folder.

Image 5

Now you can see XSL files which are used by SharePoint to render its content. Here we are using ItemStyle.xsl for enabling custom rendering.

Image 6

Thus open this XSL file and put your XSL (when we created in step two) in the bottom of the XSL as follows:

Image 7

Now the difficult things are over.

Step Four

  • Add a Content Query Web Part:

    Image 8

  • Then go to edit web part and browse your list (here our list is Our Projects):

    Image 9

  • Then go to presentation section and go a little bit down. You can see style drop down.
  • Wow... now you can see your style.

    Image 10

  • Ok, then select your custom XSL (here MySample).
  • When you select, you can see something like below:

    Image 11

  • Now you need to put actual list column names to these text boxes as follows. (Title column should use with the scope):

    Image 12

  • Then click ok to Save. Now everything is ok. You can see your new list rendering now.

    Image 13

Happy SharePoint! :)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Sri Lanka Sri Lanka
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionThanks for your article. Pin
Doan Quynh26-Sep-13 15:28
Doan Quynh26-Sep-13 15:28 
GeneralCustomize SharePoint Lists, Add Barcode Fields Inside SharePoint List Pin
Saira Riaz4-Jun-12 22:01
Saira Riaz4-Jun-12 22:01 
Thanks for a wonderful post. I came across a nice SharePoint Barcode component that really good for customizing SharePoint lists. I hope it's going to be useful. Here are the details,

Aspose.BarCode for SharePoint allows developers to insert barcode symbols in Microsoft SharePoint lists. Aspose.BarCode for SharePoint supports more than 40 of the most popular barcode symbologies including linear & 2D like Code128, Code39, Code93, EAN13, UPCA, UPCE, BooklandEAN, Interleaved2of5, MSI, Code11, Codabar, Postnet, Planet, SSCC18, PDF417, QR, DataMatrix & many more. Aspose.BarCode for SharePoint is designed to work with MS SharePoint Server 2010.

Many thanks

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.