Inserito da: madamo | Dicembre 9, 2007

Implement custom search list functionality(EN)

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);
}

}

 

 


Lascia un commento

Occorre aver fatto il login per inviare un commento

Categorie