WSS3.0 development-Filter list content (1)

Source: Internet
Author: User
In WSS3.0, the following methods can be used to filter the list content:
1) Use a view to configure filtering conditions in the view
2) Develop the filter WebPart (see this article: Compile the filter WebPart -- filter the content of the list)-but the filter can only perform exact matching and cannot perform fuzzy queries, which are greater than or less than the limit.
3) Develop a webpart query, provide a CAML query statement, and put the webpart together with the List to actively control the current list. This method is described here.
The wss list is actually a webpart: ListViewWebPart. We use SPD to open a AllItems. aspx page and go to the Code mode to see the ListViewWebPart. Note:
ListViewWebPart is a very important attribute: ListViewXml, which contains messy characters. This is the Html encoded attribute value. ListViewXml controls the ListViewWebPart
Display, including the fields to be output, query conditions, and sorting. You only need to control ListViewXml to control the output of ListViewWebPart.
So what should we do?
See the following sample code.
Public class CamlFilterWebPart: WebPart
{
Private string _ Caml;
[Personalizable (PersonalizationScope. Shared)]
[WebBrowsable]
Public string Caml
{
Set {_ Caml = value ;}
Get {return _ Caml ;}
}
Protected override void OnLoad (EventArgs e)
{
Base. OnLoad (e );
If (String. IsNullOrEmtpty (Caml) return;
Try {
Foreach (WebPart wp in this. Zone. WebParts)
{
If (wp is Microsoft. SharePoint. WebPartPages. ListViewWebPart) // first find the list webpart
{
Microsoft. SharePoint. WebPartPages. ListViewWebPart listWp =
(Microsoft. SharePoint. WebPartPages. ListViewWebPart) wp;
XmlDocument doc = new XmlDocument ();
Doc. LoadXml (istWp. ListViewXml );
XmlNode queryNode = doc. DocumentElement. SelectSingleNode ("Query ");
QueryNode. InnerXml = this.
ListWp. ListViewXml = doc. InnerXml; // Replace the Schema displayed in the list
}
}

} Catch (Exception ex)
{
This. Controls. Add (new LiteralControl (ex. Message ));
}
}
}

CamlFilterWebPart has a configurable attribute Caml that can store query conditions.
When CamlFilterWebPart is loaded, the ListViewWebPart of the same Zone is automatically obtained to control its query.
Based on this idea, we can make powerful query controls and provide any query conditions to control the list!
The next article will continue to expand the CamlFilterWebPart...

Postscript:
If the list is connected to another webpart, this method will be invalid and the list will always be displayed according to the View query conditions.
To solve this problem, force clear the view attributes of the List WebPart:
ListWp. ViewGuid = ""';

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.