how to merge same values when binding the dropdownlist?
when i bind the dropdownlist as a result i get 2 same values (like 45, 45 ,24 ,24) but
i only want (45,24 ).
How to merge same values when binding the dropdownlist?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Iftikar HussainRank #423 · 5.9K reputationPosted Jul 11, 2013, 7:06 AM EDT
Can you please provide your code? If you are binding from sql query then you can use
Select distinct col1,col1 from table1
Regards,
Iftikar
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jul 11, 2013, 7:54 AM EDT
try this code
public static void RemoveDuplicateItems(DropDownList ddl)
{
for (int i = 0; i < ddl.Items.Count; i++)
{
ddl.SelectedIndex = i;
string str = ddl.SelectedItem.ToString();
for (int counter = i + 1; counter < ddl.Items.Count; counter++)
{
ddl.SelectedIndex = counter;
string compareStr = ddl.SelectedItem.ToString();
if (str == compareStr)
{
ddl.Items.RemoveAt(counter);
counter = counter - 1;
}
}
}
}
call this method by passing the dropdownlist id.
ex- RemoveDuplicateItems(ddlemp);