In this small blog i am going to demonstrate how to remove duplicate item from dropdownlist in asp.net.Create a sample page in Vs, Drag a dropdownlist put some item like below
How to remove duplicate item from DropDownList in asp.net

Now Call the below code snippet to remove duplicate items from dropdownlist

 code snippet

  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;
                }
            }
        }
    }

Results

How to remove duplicate item from DropDownList in asp.net



  Modified On Mar-14-2018 01:02:43 AM
  1. I am grateful to you, for sharing a post like this.

Leave Comment