SetFilterEventArgs.FilterExpression 属性

请注意:此 API 现在已过时。

获取或设置SetFilterEvent发生时实现IFilterProvider接口WebPart提供的列表的筛选器表达式。

命名空间:  Microsoft.SharePoint.WebPartPages.Communication
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
<ObsoleteAttribute("Use System.Web.UI.WebControls.WebParts.IWebPartParameters instead")> _
Public Property FilterExpression As String
    Get
    Set
用法
Dim instance As SetFilterEventArgs
Dim value As String

value = instance.FilterExpression

instance.FilterExpression = value
[ObsoleteAttribute("Use System.Web.UI.WebControls.WebParts.IWebPartParameters instead")]
public string FilterExpression { get; set; }

属性值

类型:System.String
提供的筛选器表达式。

备注

FilterExpression属性组成的字段名称和按一个唯一的数字,例如 FilterField1 分组的字段值对的一系列 FieldName1 英文 FilterValue1 = FieldValue1 & FilterField2 = FieldName2 & FilterValue2 = FieldValue2。

此外可以通过排序表达式,如 FilterField1 追加 FieldName1 英文 FilterValue1 = FieldValue1 & SortField = FieldName 和 SortDir = SortDirection。如果未提供 SortField,则应该向列表应用任何排序。如果提供了 SortField,但不是 SortDirection,应按升序方向排序列表。

对于跨页连接的整个表达式将 URL 编码,例如,空格替换 %20。否则,将使用无 URL 编码。

备注

返回由FilterExpression属性的值不一定要用于筛选列表。Web 部件使用此值使用用于其他目的的名称/值对。

示例

下面的代码示例演示使用FilterExpression属性设置提供的筛选器表达式PartCommunicationsMain方法。此代码示例是示例的一个更大提供的IFilterProvider接口的一部分。

' Step #7: Override the PartCommunicationMain() method.
' The PartCommunicationMain method is called by the Web Part 
' infrastructure on the client during the ASP.NET PreRender
' event to allow the part to pass its primary data to the other 
' connected parts. It is important to always fire either the SetFilter, 
' NoFilter, or ClearFilter event. Some parts may not behave properly if 
' they are left waiting for this information.
' SetFilter should be fired to send the filter expression.
' NoFilter should be fired to indicate that there is no change in the 
' filter expression. ClearFilter should be fired to indicate that the 
' filter should be removed.
Public Overrides Sub PartCommunicationMain()
   ' Ensure that all of the Web Part's controls are created.
   EnsureChildControls()
   
   ' Check if connected.
   If _connected Then
      ' Check which button was clicked.
      If _setFilterClicked = True Then
             ' Create the SetFilterEventArgs object for the SetFilter 
             ' event.
             Dim setFilterEventArgs As New SetFilterEventArgs()
             
            ' Create the filter expression.
             Dim eIndex As Integer = 1
             Dim filterExpression As String = String.Empty
             Dim index As Integer
             For index = 0 To _fieldList.Length - 1
                ' This filter expression syntax should be used with 
                ' SharePoint lists and other Microsoft Web Parts that 
                ' support the IFilterConsumer interface.
                If _filterInputs(index).Text <> String.Empty Then
                   filterExpression += FieldLabel + eIndex.ToString() + "=" + _fieldList(index) + "&"
                   filterExpression += ValueLabel + eIndex.ToString() + "=" + _filterInputs(index).Text + "&"
                   eIndex += 1
                End If
             Next index
                  
            ' Trim Off Trailing '&'
            If filterExpression.Length <> 0 Then
               filterExpression = filterExpression.Substring(0, filterExpression.Length - 1)
            End If 
            ' Set the FilterExpression property on the 
            ' SetFilterEventArgs object.
            setFilterEventArgs.FilterExpression = filterExpression
          
            ' Set the _filterExpression variable for display in the 
            ' user interface.
            _filterExpression = filterExpression
      
           ' Fire the event.
            RaiseEvent SetFilter(Me, setFilterEventArgs)
            _setFilterClicked = False
         End If
      ElseIf _clearFilterClicked = True Then
            RaiseEvent ClearFilter(Me, New EventArgs())
            _clearFilterClicked = False
            
            ' Clear out values in input text boxes.
            If Not (_filterInputs Is Nothing) Then
               Dim index As Integer
               For index = 0 To _filterInputs.Length - 1
                  _filterInputs(index).Text = String.Empty
               Next index
            End If
      ElseIf _noFilterClicked = True Then
            RaiseEvent NoFilter(Me, New EventArgs())
            _noFilterClicked = False
     Else
            RaiseEvent NoFilter(Me, New EventArgs())
     End If
 End Sub
// Step #7: Override the PartCommunicationMain() method.
// The PartCommunicationMain method is called by the Web Part 
// infrastructure on the client during the ASP.NET PreRender
// event to allow the part to pass its primary data to the other 
// connected parts.
// It is important to always fire either the SetFilter, NoFilter, or 
// ClearFilter event. Some parts may not behave properly if they are 
// left waiting for this information.
// SetFilter should be fired to send the filter expression.
// NoFilter should be fired to indicate that there is no change in the filter expression.
// ClearFilter should be fired to indicate that the filter should be removed.
public override void PartCommunicationMain()
{
    // Ensure that all of the Web Part's controls are created.
    EnsureChildControls();

    // Check if connected.
    if(_connected)
    {
        // Check which button was clicked.
        if(_setFilterClicked == true)
        {
            // If there is a listener, fire the SetFilter event.
            if (SetFilter != null)
            {
                // Create the SetFilterEventArgs object for the SetFilter event.
                SetFilterEventArgs setFilterEventArgs = new SetFilterEventArgs();

                // Create the filter expression.
                int eIndex = 1;
                string filterExpression = string.Empty;
                for (int index = 0; index < _fieldList.Length; index++)
                {
                    // This filter expression syntax should be used 
                    // with SharePoint lists
                    // and other Microsoft Web Parts that support the 
                    // IFilterConsumer interface.
                    if (_filterInputs[index].Text != string.Empty)
                    {
                        filterExpression += FieldLabel + eIndex.ToString() + "=" + _fieldList[index] + "&";
                        filterExpression += ValueLabel + eIndex.ToString() + "=" + _filterInputs[index].Text + "&";
                        eIndex++;
                    }
                }

                // Trim Off Trailing '&'
                if (filterExpression.Length != 0)
                    filterExpression = filterExpression.Substring(0,filterExpression.Length - 1);

                // Set the FilterExpression property on the 
                // SetFilterEventArgs object.
                setFilterEventArgs.FilterExpression = filterExpression;

                // Set the _filterExpression variable for display in 
                // the user interface.
                _filterExpression = filterExpression;

                // Fire the event.
                SetFilter(this, setFilterEventArgs);

                _setFilterClicked = false;
            }
        }
        else if(_clearFilterClicked == true)
        {
            // If there is a listener, fire the ClearFilter event.
            if (ClearFilter != null)
            {
                ClearFilter(this, new EventArgs());

                _clearFilterClicked = false;

                // Clear out values in input text boxes.
                if (_filterInputs != null)
                {
                    for (int index = 0; index < _filterInputs.Length; index++)
                        _filterInputs[index].Text = string.Empty;
                }
            }
        }
        else if(_noFilterClicked == true)
        {
            // If there is a listener, fire the NoFilter event.
            if (NoFilter != null)
            {
                NoFilter(this, new EventArgs());

                _noFilterClicked = false;
            }
        }
        else
        {
            // If there is a listener, fire the NoFilter event.
            if (NoFilter != null)
            {
                NoFilter(this, new EventArgs());
            }
        }
    }
}

另请参阅

引用

SetFilterEventArgs 类

SetFilterEventArgs 成员

Microsoft.SharePoint.WebPartPages.Communication 命名空间