Declare the
StringBuilder
class before the
while
loop. Combine multiple filters with
OR
. Assign the
RowFilter
and return the result after the
while
loop.
You should also be able to use a
foreach
loop, rather than working directly with the
IEnumerator
interface.
var sb = new StringBuilder();
foreach (Microsoft.SharePoint.WebControls.PickerEntity item in UserPicker.ResolvedEntities)
{
SPUser selectedUser = web.EnsureUser(item.Key);
string strVendorUserName = selectedUser.LoginName;
if (strVendorUserName != null || ddlPermissionType.SelectedItem != null)
{
if (sb.Length != 0) sb.Append(" OR ");
sb.AppendFormat("UserLoginName = '{0}'", strVendorUserName.Trim());
}
}
dv.RowFilter = sb.ToString();
return dv;
NB: Looking at your
if
block, you believe that
LoginName
could return
null
. But if it does, and
ddlPermissionType.SelectedItem
is
not null
, then
strVendorUserName.Trim()
will fail with a
NullReferenceException
.