IFilterConsumer.SetFilter - Méthode
Remarque : cette API est désormais obsolète.
Répond à une demande de définition d'un filtre à partir de l'événement SetFilter d'un composant WebPart fournisseur.
Espace de noms : Microsoft.SharePoint.WebPartPages.Communication
Assembly : Microsoft.SharePoint (dans Microsoft.SharePoint.dll)
Syntaxe
'Déclaration
<ObsoleteAttribute("Use System.Web.UI.WebControls.WebParts.IWebPartParameters instead")> _
Sub SetFilter ( _
sender As Object, _
setFilterEventArgs As SetFilterEventArgs _
)
'Utilisation
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
)
Paramètres
sender
Type : System.ObjectUne référence à l'objet qui implémente l'interface IFilterProvider sur le composant WebPart fournisseur.
setFilterEventArgs
Type : Microsoft.SharePoint.WebPartPages.Communication.SetFilterEventArgsUn objet SetFilterEventArgs est reçu à partir de l'événement SetFilter qui décrit le filtre à utiliser pour le composant WebPart consommateur.
Exemples
L'exemple de code suivant illustre une implémentation de gestionnaire d'événements SetFilter . Cet exemple de code fait partie d'un exemple plus développé fourni pour l'interface 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;
}
}
}
Voir aussi
Référence
Microsoft.SharePoint.WebPartPages.Communication - Espace de noms