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:
- Create CAML Query, on client using javascript code
- Using HTML hidden input field send CAML to server
- 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);
}
}