编写过滤器WebPart--过滤列表内容

本文介绍如何在SharePoint中开发WebPart过滤器,实现对列表内容的精确匹配筛选。通过实现IWebPartParameters接口,设置过滤条件及过滤值。
先看代码:

using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using System.Collections;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.ComponentModel;

namespace MyPart
{
    [Guid(
"9eb18c96-ce55-4a8b-8e08-e6db886c0320")]
    
public class MyPart : Microsoft.SharePoint.WebPartPages.WebPart, IWebPartParameters 
    {
        
public MyPart()
        {
            
this.ExportMode = WebPartExportMode.All;
        }

        
protected override void Render(HtmlTextWriter writer)
        {
            writer.Write( 
"hello,world!" );
        }

        
#region other connecton interfaces
        
//[ConnectionConsumer("IWebPartField", "IWebPartField")]
        
//public void SetObj( IWebPartField f )
        
//{
        
//}

        
//[ConnectionConsumer("IWebPartRow", "IWebPartRow")]
        
//public void SetObj(IWebPartRow f)
        
//{
        
//}

        
//[ConnectionConsumer("IWebPartTable", "IWebPartTable")]
        
//public void SetObj(IWebPartTable f)
        
//{
        
//}
        #endregion

        [ConnectionProvider(
"IWebPartParameters""IWebPartParameters")]
        
public IWebPartParameters ProviderIWebPartParameters()
        {
            
return this;
        }
        
#region IWebPartParameters 成员
        
public void GetParametersData(ParametersCallback callback)
        {
            
//此处按照_schema的字段名返回过滤依据
            IDictionary dic = new Hashtable();
            
//dic.Add("KeyWord" , this.KeyWord );
            dic.Add("LinkTitle""XXX"); //按照标题过滤
            callback(dic);
        }
        
public System.ComponentModel.PropertyDescriptorCollection Schema
        {
            
get 
            {
                
return _schema;              

                
//PropertyDescriptorCollection properties =
                
//    TypeDescriptor.GetProperties(this, new Attribute[] { new WebBrowsableAttribute() });
                
//return properties;
            }
        }
        
private PropertyDescriptorCollection _schema;
        
public void SetConsumerSchema(System.ComponentModel.PropertyDescriptorCollection schema)
        {
            _schema 
= schema;
        }
        
#endregion
    }
}


将以上webpart拖入一个通知列表的AllItems.aspx页面,在编辑模式下,选择  编辑-〉连接-IWebPartParameters发送对象-〉当前的列表,
可以看到效果:列表只有标题为XXX的项目显示出来。

在MOSS中有很多过滤器WebPart,可以来过滤列表的内容,而WSS中是没有的,这些过滤器是如何开发的呢?
很简单,只要过滤器WebPart实现IWebPartParameters即可。
 
 public void SetConsumerSchema(System.ComponentModel.PropertyDescriptorCollection schema)
        
{
            _schema 
= schema;
        }
此方法设置目标webpart(通常是一个ListViewWebPart)的可过滤参数。

  public System.ComponentModel.PropertyDescriptorCollection Schema
        
{
            
get 
            
{
                
return _schema;                    
            }

        }
这个属性返回过滤器提供的过滤参数。

 public void GetParametersData(ParametersCallback callback)
        
{
            
//此处按照_schema的字段名返回过滤依据
            IDictionary dic = new Hashtable();
            
//dic.Add("KeyWord" , this.KeyWord );
            dic.Add("LinkTitle""XXX"); //按照标题过滤

            callback(dic);
        }
此方法设置过滤值,使被过滤得列表只显示标题为XXX的题目。

过滤器可以实现对列表某个字段的过滤(多个字段应该也可以)。但是可惜的是,通过过滤器只能做到精确匹配筛选,无法进行模糊查询。



转载于:https://www.cnblogs.com/jianyi0115/archive/2008/01/06/1027691.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值