SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What do i need to do in my itemStyle.xsl to hide webpart when there are no items. When RowCount is 0. Thanks i advance

share|improve this question

if you got access to your webpart code then, by default make it invisible. then you can use two event receivers one for item adding to make webpart visible and another one for item deleting as if a item is deleted check if list is empty if it is then hide webpart.

you can access your webpart properties by referencing it using its dll in event receivers.

protected void webpartproperties(SPWeb web)
            web.AllowUnsafeUpdates = true;
            SPWebPartCollection wpcWebParts = web.GetWebPartCollection(PageUrl, Storage.Shared);
            foreach (Microsoft.SharePoint.WebPartPages.WebPart wptWebPart in wpcWebParts)
                string titl = wptWebPart.Title;
                if (wptWebPart.ZoneID != "Top")
                    wptWebPart.Hidden = true;
            web.AllowUnsafeUpdates = false;

you can access more properties over here

msdn webpart properperties

share|improve this answer
Thanks guys. Also if number of list items is 0 how can i get the CQWP to show "No items can be displayed in this view" just like in DVWP? – naijacoder Jul 17 '12 at 0:18

You can't control the visibility of the CQWP from the ItemStyle.xsl. That file only helps display items in the webpart, not control the visibility of it.

To control the visibility you'd have to either create your own webpart inheriting the CQWP or make some javascript which hides it.

share|improve this answer

Your Answer


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.