Compartir a través de


del método IFilterConsumer.SetFilter

NOTA: esta API está ahora obsoleta.

Responde a una solicitud para establecer un filtro desde el evento SetFilter de un elemento Web del proveedor.

Espacio de nombres:  Microsoft.SharePoint.WebPartPages.Communication
Ensamblado:  Microsoft.SharePoint (en Microsoft.SharePoint.dll)

Sintaxis

'Declaración
<ObsoleteAttribute("Use System.Web.UI.WebControls.WebParts.IWebPartParameters instead")> _
Sub SetFilter ( _
    sender As Object, _
    setFilterEventArgs As SetFilterEventArgs _
)
'Uso
Dim instance As IFilterConsumer
Dim sender As Object
Dim setFilterEventArgs As SetFilterEventArgs

instance.SetFilter(sender, setFilterEventArgs)
[ObsoleteAttribute("Use System.Web.UI.WebControls.WebParts.IWebPartParameters instead")]
void SetFilter(
    Object sender,
    SetFilterEventArgs setFilterEventArgs
)

Parámetros

  • sender
    Tipo: System.Object

    Una referencia al objeto que implementa la interfaz IFilterProvider en el elemento Web del proveedor.

Ejemplos

En el ejemplo de código siguiente se muestra una implementación del controlador de eventos SetFilter . Este ejemplo de código forma parte de un ejemplo más extenso de la interfaz IFilterConsumer .

' Step #9: Implement the SetFilter event handler.
' The connected provider part will call this method during its 
' PartCommunicationMain phase to set the filter on the 
' consumer Web Part.
' <param name="sender">Provider Web Part</param>
' <param name="SetFilterArgs">The args passed by the Provider</param>
Public Sub SetFilter(sender As Object, setFilterEventArgs As SetFilterEventArgs) Implements IFilterConsumer.SetFilter
   ' Ensure that all of the Web Part's controls are created.
   EnsureChildControls()
   
   ' Convert FilterExpression to the DataTable RowFilter syntax.
   If Not (setFilterEventArgs.FilterExpression Is Nothing) Then

      ' Parse the filter information.
      Dim values As String() = setFilterEventArgs.FilterExpression.Split(New [Char]() {"&"c})
      If values.Length > 1 Then
         Dim j As Integer = 1 'counts the number of Field/Value pairs
         Dim filterField As String = String.Empty
         Dim filterValue As String = String.Empty
         Dim filterAnd As String = " AND "
         _rowFilterExpression = String.Empty
         
         Dim i As Integer
         For i = 0 To values.Length - 1
            ' Clear values.
            filterField = String.Empty
            filterValue = String.Empty
      
            ' Create label portion of name/value pairs.
            Dim currField, currValue As String
            currField = FieldLabel + j.ToString() + "="
            currValue = ValueLabel + j.ToString() + "="
            j += 1
      
            ' Extract just the field name by replacing the rest of the 
            ' string with string.Empty.
            filterField = filterField + values(i).Replace(currField, String.Empty)
            
            ' Move to next item in the array which is the value 
            ' component.
            i += 1

            ' Extract just the Value by replacing the rest of the 
            ' string with string.Empty.
            filterValue = filterValue + values(i).Replace(currValue, String.Empty)
      
            ' Contruct the row filter expression.
            _rowFilterExpression += filterField + "=" + "'" + filterValue + "'" + filterAnd
         Next i 
         ' Trim Off the trailing 'And'.
         If _rowFilterExpression.Length <> 0 Then
            _rowFilterExpression = _rowFilterExpression.Substring(0, _rowFilterExpression.Length - filterAnd.Length)
         End If 
         ' Store _rowFilterExpression for use by NoFilter event.
         _cachedRowFilter.Text = _rowFilterExpression
      End If
   End If
End Sub
// Step #9: Implement the SetFilter event handler.
// The connected provider part will call this method during its 
// PartCommunicationMain phase to set the filter on the consumer 
// Web Part.
// <param name="sender">Provider Web Part</param>
// <param name="SetFilterArgs">The args passed by the Provider</param>

public void SetFilter(object sender, SetFilterEventArgs setFilterEventArgs)
{
    // Ensure that all of the Web Part's controls are created.
    EnsureChildControls();

    // Convert FilterExpression to the DataTable RowFilter syntax.
    if(setFilterEventArgs.FilterExpression != null)
    {

        // Parse the filter information.
        string[] values = setFilterEventArgs.FilterExpression.Split(new Char[] {'&'});
        if (values.Length > 1)
        {
            int j = 1;  //counts the number of Field/Value pairs
            string filterField = string.Empty;
            string filterValue = string.Empty;
            string filterAnd = " AND ";
            _rowFilterExpression = string.Empty;

            for(int i=0; i < values.Length; i++)
            {
                // Clear values.
                filterField = string.Empty;
                filterValue = string.Empty;

                // Create label portion of name/value pairs.
                string currField, currValue;
                currField = FieldLabel + j + "=";
                currValue = ValueLabel + j + "=";
                j++;  
                    
                // Extract just the field name by replacing the rest of 
                // the string with string.Empty.
                filterField = filterField + values[i].Replace(currField, string.Empty);
                    
                // Move to next item in the array which is the value 
                // component.
                i++;
                
                // Extract just the Value by replacing the rest of the 
                // string with string.Empty.
                filterValue = filterValue + values[i].Replace(currValue, string.Empty);

                // Contruct the row filter expression.
                _rowFilterExpression += filterField + "=" + "'" + filterValue + "'" + filterAnd;

            }
            // Trim Off the trailing 'And'.
            if (_rowFilterExpression.Length != 0)
                _rowFilterExpression = _rowFilterExpression.Substring(0,_rowFilterExpression.Length - filterAnd.Length);

            // Store _rowFilterExpression for use by NoFilter event.
            _cachedRowFilter.Text = _rowFilterExpression;
        }
    }
}

Vea también

Referencia

interfaz IFilterConsumer

Miembros IFilterConsumer

Espacio de nombres Microsoft.SharePoint.WebPartPages.Communication