あなたのコメントから:
ASP.NETフォームには、customerCheckLという名前のCheckBoxListがあります。データファイルをロードすると、コードはcustomerCheckL.Itemsに個別の顧客名のリストを入力する必要があります。それ、どうやったら出来るの?customerCheckL.DataSourceID = ???
それはもっと理にかなっています。EqulityComparer<transactions>
顧客ごとに比較するクラスを実装できます。
public class TransactionCustomerComparer : IEqualityComparer<transaction>
{
public bool Equals(transaction x, transaction y)
{
if (x == null || y == null) return false;
return x.customerName == y.customerName;
}
public int GetHashCode(transaction obj)
{
if (obj == null) return int.MinValue;
return obj.customerName.GetHashCode();
}
}
Enumerable
(このメソッドは、カスタム比較子を渡すことができるすべてのメソッドで使用できることに注意してください)
次に、を使用Distinct
して一意のリストを取得できます。DataSource
、、DataTextField
および DataValueField
を設定するだけDataBind
ですCheckBoxList
。
var customerComparer = new TransactionCustomerComparer();
customerCheckL.DataSource = transactions.Distinct(customerComparer);
customerCheckL.DataTextField = "customerName";
customerCheckL.DataValueField = "transactionNum";
customerCheckL.DataBind();