2017-03-02 42 views
0

我有這個頁面的運算符有兩個表,其中包含來自數據庫的數據,帶有現有運算符的一個表和帶有現有用戶的一個表。如果用戶已經是操作員,我希望該行在表格中隱藏。這裏是我的代碼:帶數據集的數據行篩選數組c#net淨

C#:

 var userDetailsList = new List<ContactPartial>(); 
     TellusAPI.TellusUserDetails userDetails; 

     var operators = _administrationSystem.GetOperatorsInformation(userId); //DataSet 
     var getUser = webSearch.DoSearchForNameAndNumber(userId, txtSearchForOperator.Text, false, "", "", false, false, out userDetails); //Array 

     if (getUser == null) 
     { 
      userDetailsList.Add(new ContactPartial(userDetails)); 
      rptAdd.DataSource = null; 
     } 

     else 
     { 
      userDetailsList = getUser.Select(x => new ContactPartial(x)).ToList(); 

      var dv = new DataView(operators.Tables[0]); 

      foreach (var Operator in userDetailsList) 
      { 
       if (!userDetailsList.Contains(Operator)) continue; 
       dv.RowFilter = "ID = " + Operator.Id; 
      } 

      rptAdd.DataSource = userDetailsList; //Repeater 
     } 

類:

/// <summary> 
/// Class for converting. 
/// </summary> 
public class ContactPartial 
{ 
    public long Id { get; set; } 
    public string FirstName { get; set; } 
    public string LastName { get; set; } 
    public string CompanyName { get; set; } 
    public string Email { get; set; } 

    public ContactPartial(TellusUserDetails tud) 
    { 
     if (tud == null) 
     { 
      return; 
     } 

     Id = tud.UserID; 
     FirstName = tud.FirstName; 
     LastName = tud.LastName; 
     CompanyName = tud.Organisation.Description; 
     Email = tud.Email; 
    } 

    public ContactPartial(TellusSearchUserInfo tsi) 
    { 
     if (tsi == null) 
     { 
      return; 
     } 

     Id = tsi.ID; 
     FirstName = tsi.FirstName; 
     LastName = tsi.LastName; 
     CompanyName = tsi.CompanyName; 
     Email = tsi.Email; 
    } 
} 

所以我現在比較這兩個,並與ID過濾行,但它仍然讀取所有行。

+0

你能提供一些示例數據和預期結果,並在你的代碼哪行做什麼和不做什麼,預計一些解釋? –

+0

預期的結果是,當您搜索數據庫中的用戶時,您想要過濾掉已包含在操作員表中的那些用戶。我有應該知道的ID。 – Malphai

+0

@ChetanRanpariya請閱讀評論。 – Malphai

回答

1
 foreach (var Operator in userDetailsList) ****** 
     { 
      if (!userDetailsList.Contains(Operator)) continue; 
      dv.RowFilter = "ID = " + Operator.Id; 
     } 

我看到命名約定的一些問題。您應該正確地通知什麼是運算符以及什麼是用戶詳細信息對象。不要混淆。

 foreach (var user in userDetailsList) 
     { 
      // Since dv is the one which contain operator details 
      if (dv.Select("ID= '" + user.Id + "'").Count > 0) 
      { 
      dv.RowFilter = "ID = " + user.Id; 
      } 
     } 
+0

是的,你的代碼不正確,我不能使用'dv.Select',因爲在IntelliSense中沒有對'DataView'的選擇。 – Malphai

+0

你可以使用dv.Table.Select – Sailor