none
Two ListViewByQuery controls in a single page - grouping doesn't work properly

    Question

  • Hi,

    I have created a sharepoint application page where two ListViewByQuery controls exist in order to display two document libraries from different sites, but within the same site collection.

    Those document libraries have views where the documents are grouped.

    I could display these views in the ListViewByQuery controls correctly.

    But my problem is when I click the second group (the + or - mark) to expand or collapse, it clicks the first group of the first ListViewByQuery control and collapse of expand that; Not the one I click.

    But first control works properly.

    This is my application page.

    <%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    
    <%@ Assembly Name="CustomAppPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=bb1cded86b3255c6" %>
    
    
    
    <%@ Register TagPrefix="spuc" Namespace="Microsoft.SharePoint.WebControls"
    
        Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    
        
    
    <%@ Page Language="C#" MasterPageFile="~/_layouts/application.master" AutoEventWireup="true" CodeBehind="DocumnetLibraryViewerPage.aspx.cs" Inherits="CustomAppPages.DocumnetLibraryViewerPage" %>
    
    
    
    <asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    
    
    
    <div id="ViewDiv">
    
      <spuc:ListViewByQuery ID="DocumentsListViewByQuery" runat="server" Width="700px" />
    
    </div>
    
    
    
    
    
    <div id="ViewDiv2">
    
      <spuc:ListViewByQuery ID="DocumentsListViewByQuery2" runat="server" Width="700px" />
    
    </div>
    
    </asp:Content>
    
    

    And this is the code behind:

    using System;
    
    using System.Collections;
    
    using System.Configuration;
    
    using System.Data;
    
    using System.Linq;
    
    using System.Web;
    
    using System.Web.Security;
    
    using System.Web.UI;
    
    using System.Web.UI.HtmlControls;
    
    using System.Web.UI.WebControls;
    
    using System.Web.UI.WebControls.WebParts;
    
    using System.Xml.Linq;
    
    using Microsoft.SharePoint.WebControls;
    
    using Microsoft.SharePoint;
    
    
    
    namespace CustomAppPages
    
    {
    
     public partial class DocumnetLibraryViewerPage : System.Web.UI.Page
    
     {
    
      protected ListViewByQuery DocumentsListViewByQuery, DocumentsListViewByQuery2;
    
      protected void Page_Load(object sender, EventArgs e)
    
      {
    
       using (SPSite site = new SPSite("siteURL"))
    
       {
    
        using (SPWeb web = site.OpenWeb())
    
        {
    
         SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists["documentLibraryName1"];
    
         if (docLib != null)
    
         {
    
          DocumentsListViewByQuery.List = docLib;
    
          SPQuery spQueryObj = new SPQuery(DocumentsListViewByQuery.List.Views["All Documents"]);
    
          string query = spQueryObj.Query;      
    
          spQueryObj.Query = query;
    
          DocumentsListViewByQuery.Query = spQueryObj;
    
         }
    
        }
    
       }
    
    
    
       using (SPSite site = new SPSite("siteURL"))
    
       {
    
        using (SPWeb web = site.OpenWeb())
    
        {
    
         SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists["documentLibraryName2"];
    
         if (docLib != null)
    
         {
    
          DocumentsListViewByQuery2.List = docLib;
    
          SPQuery spQueryObj = new SPQuery(DocumentsListViewByQuery.List.Views["All Documents"]);
    
          string query = spQueryObj.Query;      
    
          spQueryObj.Query = query;
    
          DocumentsListViewByQuery2.Query = spQueryObj;
    
         }
    
        }
    
       }
    
      }
    
     }
    
    }
    
    
    
    

    I checked the source of the page and it seems that both the control have the same namings when they call the ExpCollGroup javascript function.

    first control

    <a href="javascript:" onclick="javascript:ExpCollGroup('1-1_','img_1-1_');return false;"><img id="img_1-1_" src="/_layouts/images/minus.gif" alt="Expand/Collapse" border="0">

    <a href="javascript:" onclick="javascript:ExpCollGroup('1-1_1_','img_1-1_1_');return false;"><img id="img_1-1_1_" src="/_layouts/images/minus.gif" alt="Expand/Collapse" border="0">

    <a href="javascript:" onclick="javascript:ExpCollGroup('1-1_2_','img_1-1_2_');return false;"><img id="img_1-1_2_" src="/_layouts/images/minus.gif" alt="Expand/Collapse" border="0">

    <a href="javascript:" onclick="javascript:ExpCollGroup('1-2_','img_1-2_');return false;"><img id="img_1-2_" src="/_layouts/images/minus.gif" alt="Expand/Collapse" border="0">

    etc.

    second control is also rendered in the same way

    <a href="javascript:" onclick="javascript:ExpCollGroup('1-1_','img_1-1_');return false;"><img id="img_1-1_" src="/_layouts/images/minus.gif" alt="Expand/Collapse" border="0">

    <a href="javascript:" onclick="javascript:ExpCollGroup('1-1_1_','img_1-1_1_');return false;"><img id="img_1-1_1_" src="/_layouts/images/minus.gif" alt="Expand/Collapse" border="0">

    <a href="javascript:" onclick="javascript:ExpCollGroup('1-1_2_','img_1-1_2_');return false;"><img id="img_1-1_2_" src="/_layouts/images/minus.gif" alt="Expand/Collapse" border="0">

    <a href="javascript:" onclick="javascript:ExpCollGroup('1-2_','img_1-2_');return false;"><img id="img_1-2_" src="/_layouts/images/minus.gif" alt="Expand/Collapse" border="0">

    etc.

    I think that's why when I click the grouping of the second control it expands or collapses the groups of the first one.

    Any solution for this please?

    Thanks in advance.

    -Sachith

     

    Wednesday, July 21, 2010 8:48 AM

All replies

  • this control uses javascript that is not rendered as unique to the control. that means only one of them will work at a time. I can't think of a solution short of developing your own control...
    Ishai Sagi, SharePoint MVP MCTS in SharePoint Development (WSS & MOSS) Author (2007 how to book): www.tinyurl.com/sharepointbook Author (2010 how to book): www.tinyurl.com/sharepointbook2010 Blog: http://www.sharepoint-tips.com Company: http://www.extelligentdesign.com
    Thursday, July 22, 2010 1:41 AM
  • this control uses javascript that is not rendered as unique to the control. that means only one of them will work at a time. I can't think of a solution short of developing your own control...
    Ishai Sagi, SharePoint MVP MCTS in SharePoint Development (WSS & MOSS) Author (2007 how to book): www.tinyurl.com/sharepointbook Author (2010 how to book): www.tinyurl.com/sharepointbook2010 Blog: http://www.sharepoint-tips.com Company: http://www.extelligentdesign.com

    Hi Ishai,

    Will you please elaborate in detail? Right now what i understand is we can not use Two ListviewByQuery control on same page. is that right? i am facing the same problem and i have to use multiple ListViewByQuery in same page.

    Thanks


    Wednesday, March 20, 2013 3:55 PM