Abhilash J A

Abhilash J A

  • 534
  • 2.4k
  • 597.2k

How to comparing multiple itemname in the same list using c#

Jan 5 2016 8:29 AM
How to compare same names from List items (like ItemName==ItemName(eg:- car is duplicated 3 times)) using c# code?

This is my SQL Procedure Result:-

Id        ItemName

1370 Air Freshner
2484 Air Freshner
604 Airbed Item
718 Alarm Clock
2576 Alarm Clock
2834 All terrain transporter
1618 App
2938 App
2509 Apple Juice Carton
321 Apple Sauce Jar
1086 Can
606 Car
966 Car

How to write in c# code:-

Here "tempList" is contain list ItemName with id from my sql query I try,

foreach (var item in tempList)
{
If(item.ItemName=="Car"){
ItemList.Add(new SelectListItem { Text = item.ItemName, Value = item.Id.ToString() });
}
}
In this 'tempList' contains query result in List<> format. Then How to compare same 'ItemName' like (if there is 3 car (same name) then campare like ==) from procedure and append there ids like (Value = "1086,606,966") in checkbox Text

Answers (2)