How can one remove duplicate items from dropdownlist in asp.net making sure that only unique values are listed in dropdownlist
Sorry if this is the duplicate question. Searched the SO but couldn’t find it.
UPDATED CODE:
private void BindDropdown(DropDownList ddlColumn)
{
DataTable dtBinddropDown = new DataTable();
DataSet dsBinddrodown = new DataSet("dsSample");
dtBinddropDown = (DataTable)Session[GlobalConstants.SESSION_MYSESSION];
dsBinddrodown.Tables.Add(dtBinddropDown.Copy());
System.Collections.ArrayList arItems = new System.Collections.ArrayList();
if (ddlColumn.ID == "ddlEntryDate")
{
for (int i = 1; i < dsBinddrodown.Tables[0].Rows.Count; i++)
{
arItems.Add(dsBinddrodown.Tables[0].Rows[i]["Column 1"].ToString());
}
ddlColumn.DataSource = arItems;
ddlColumn.DataBind();
}
}
Thanks
if your datasource uses a generic list, you could use LINQ to clear any duplicates before you bind it to your dropdown control – im assuming your using webforms ?
this is what i have used to remove duplicate vehicle objects on my site using the VehicleID, but the same would apply to your dropdown.
hope that helps
Truegilly