private void BindDataGrid(bool dataBind) { string sSearch = tbSearchString.Text.Trim(); int iGroupId = int.Parse(ddGroups.SelectedValue); DataTable dtSource = new DataTable(); switch (_objectTypeId) { case (int)ObjectTypes.ToDo: case (int)ObjectTypes.Task: if (!String.IsNullOrEmpty(sSearch)) { dtSource = User.GetListUsersBySubstringDataTable(sSearch); } else if (iGroupId > 0) { dtSource = SecureGroup.GetListActiveUsersInGroupDataTable(iGroupId); } else { dtSource = Project.GetListTeamMemberNamesWithManagerDataTable(-iGroupId); } break; default: break; } DataTable dt = ((DataTable)ViewState["Resources"]).Copy(); foreach (DataRow dr in dt.Rows) { DataRow[] drMas = dtSource.Select("UserId = " + (int)dr["UserId"]); if (drMas.Length > 0) { dtSource.Rows.Remove(drMas[0]); } } grdMain.DataSource = dtSource.DefaultView; if (dataBind) { grdMain.DataBind(); } }