2013-04-26 2 views
0

나는 사용자가 새 데이터를 삽입 할 때 우리의 목록에 이미 동일한 데이터가 있는지를 확인하기 위해 몇 가지 드롭 다운, 원하는 것은 무엇입니까?목록에서 중복을 중지

내 코드는 _priceSystems 목록 <이 여기

if(ViewState["_priceSystems"]!=null) 
    _priceSystems=ViewState["_priceSystems"] as TList<PriceSystemItems>; 

bool _isTrue= 
    PriceSystemExist(
     _priceSystemItems.PricePlanId, 
     _priceSystemItems.SurchargePlanId, 
     _priceSystemItems.NoMatchAltPlanId); 

if(_isTrue==false) { 
    _priceSystems.Add(_priceSystemItems); 
} 

내가 추가하고 값처럼>과 내가 값을 확인하고 코드 아래

public bool PriceSystemExist(
    int PricePlanId, int SurchagePlanId, int _noPlaneId) { 
    bool isExits=false; 

    if(ViewState["_priceSystems"]!=null) 
     _priceSystems=ViewState["_priceSystems"] as TList<PriceSystemItems>; 
    try { 
     if(_priceSystems!=null) { 
      foreach(PriceSystemItems item in _priceSystems) { 
       if(
        item.PricePlanId==_priceSystemItems.PriceSystemId 
        && 
        item.ServiceTypeId==_priceSystemItems.ServiceTypeId 
        && 
        item.NoMatchAltPlanId==_priceSystemItems.NoMatchAltPlanId) { 
        isExits=true; 
       } 
      } 
     } 
    } 
    catch(Exception ex) { 
    } 

    return isExits; 
} 

내가 돈을 목록에 존재 여부입니다 foreach 루프의 값을 확인하기 위해 내가 잘못하고있는 것을 이해하지 못합니다.

답변

0

변화 당신은 PriceSystemExist(int PricePlanId, int SurchagePlanId, int _noPlaneId) 방법에 매개 변수를 사용하지 않는

public bool PriceSystemExist(int PricePlanId, int SurchagePlanId, int _noPlaneId) 
    { 
     bool isExits = false; 
     if (ViewState["_priceSystems"] != null) 
     _priceSystems = ViewState["_priceSystems"] as TList<PriceSystemItems>; 
    try 
    { 
     if(_priceSystems != null) 
     { 
      foreach (PriceSystemItems item in _priceSystems) 
     { 
      if (item.PricePlanId == PricePlanId && item.ServiceTypeId == SurchagePlanId && item.NoMatchAltPlanId == _noPlaneId) 
     { 
      isExits = true; 
     } 
    } 
    } 

} 
catch (Exception ex) 
{ 

} 

return isExits; 
} 
0

로을 비교 한 방법. 조건부의

사용

PricePlanId 
SurchagePlanId 
_noPlaneId 

대신

_priceSystemItems.PriceSystemId 
_priceSystemItems.ServiceTypeId 
_priceSystemItems.NoMatchAltPlanId 

.

foreach (PriceSystemItems item in _priceSystems) 
{ 
     if (item.PricePlanId == PricePlanId && 
      item.ServiceTypeId == SurchagePlanId && 
      item.NoMatchAltPlanId == _noPlaneId) 
     { 
      isExits = true; 
     } 
} 

그리고 _ 접두사를 섞어서는 안됩니다.

관련 문제