先看代码:
将以上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的题目。
过滤器可以实现对列表某个字段的过滤(多个字段应该也可以)。但是可惜的是,通过过滤器只能做到精确匹配筛选,无法进行模糊查询。
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
}
}
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即可。




















过滤器可以实现对列表某个字段的过滤(多个字段应该也可以)。但是可惜的是,通过过滤器只能做到精确匹配筛选,无法进行模糊查询。
分类:
Sharepoint
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· [AI/GPT/综述] AI Agent的设计模式综述