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

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
    
accept rate 41% :/ –  Muhammad Raja Jul 16 '12 at 8:33
add comment

2 Answers

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
add comment

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;
                    wptWebPart.update();
                    break;
                }
            }
            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
add comment

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.