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
2 Answers
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
-
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? Jul 17, 2012 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.