zoukankan      html  css  js  c++  java
  • 编写过滤器WebPart过滤列表内容

    先看代码:

    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的题目。

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



  • 相关阅读:
    Vue-router的实现原理
    get请求被浏览器跨域的同源策略请求机制拦截,但是get请求是否请求到了服务器呢
    合并两个有序链表
    JS实现链式调用 a().b().c()
    CSS知识点总结
    BK-信息查找、摘取
    radar图生成用户guideline
    【转】 mybatis 详解(七)------一对一、一对多、多对多
    【转】 mybatis 详解(六)------通过mapper接口加载映射文件
    【转】 mybatis 详解(五)------动态SQL
  • 原文地址:https://www.cnblogs.com/jianyi0115/p/1027691.html
Copyright © 2011-2022 走看看