in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

Madamo working experience about Sharepoint

Talking about sharepoint real world

Advanced list search functionality

Implement a custom search list functionality, users can select muliple criteria based of
list field.
To accomplish this, i developed a custom web part solution that:
  1. Create CAML Query, on client using javascript code
  2. Using HTML hidden input field send CAML to server
  3. A second web part read CAML and render results using ListViewByQuery.
How to use ListViewByQuery:
 
    public class ModuloRicercaBase : WebPart
       
    {
        public ModuloRicercaBase()
        {
            this.ExportMode =System.Web.UI.WebControls.WebParts.WebPartExportMode.None;
        }

        private ListViewByQuery myListView;
        private SPList myList;
        private SPQuery myQuery;

        protected override void CreateChildControls()
        {
            Utility.WriteLog("CreateChildControls");
            base.CreateChildControls();
                   myListView = new ListViewByQuery();
                   myQuery = new SPQuery();
                   SPWeb myWeb= SPContext.Current.Web;
                   myWeb.Open();
                   SPList myList = myWeb.Lists["<Your List>"];
                   SPView myCustomView= myList.Views["Your View"];                  
                    myCustomView.Query = "<Your custom CAML query>";
                   myCustomView.Update();
                   myQuery.ViewXml = myCustomView.SchemaXml;
                   myListView.List = myList;
                   myListView.Query = myQuery;
                   this.Controls.Add(myListView);
           


        }
        protected override void RenderContents(HtmlTextWriter writer)
        {
            if(myListView!=null)
                myListView.RenderControl(writer);
        }
      
    }
 
 

Comments

 

Paul Galvin said:

This is very interesting.

I think I understand what you're doing here, but can you post some screen shots?

--Paul G

December 8, 2007 9:05 AM
 

madamo said:

Hi Paul,

one screen shots for you!

madamo.files.wordpress.com/.../screeshot.jpg

Rendering is not complex, it is more interesting the method for builing the CAML using javascript..

December 8, 2007 2:13 PM
 

Links (12/9/2007) « Steve Pietrek’s SharePoint Stuff said:

Pingback from  Links (12/9/2007) &laquo; Steve Pietrek&#8217;s SharePoint Stuff

December 9, 2007 4:50 PM
 

SharePoint Link love: 12-10-2007 at Virtual Generations said:

Pingback from  SharePoint Link love: 12-10-2007 at  Virtual Generations

December 10, 2007 4:08 AM
 

jbuelna said:

You need not create/update an SPView.  The following will suffice:

using Microsoft.SharePoint;

using Microsoft.SharePoint.WebControls;

. . .

SPWeb web = SPContext.Current.Web;

ListViewByQuery listView = new ListViewByQuery();

listView.List = web.Lists["List Name"];

SPQuery query = new SPQuery(listView.List.DefaultView);

query.Query = "<Where></Where>";

this.Controls.Add(listView);

February 13, 2008 9:12 AM
 

madamo said:

i'm agree with you

February 14, 2008 5:53 AM

Leave a Comment

(required )  
(optional )
(required )  
Add

Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts