I have a RadGrid that I populate from SQL database with shipment info and I am trying to populate a dropdown box with each City that appears on the grid. I haven't been able to figure out how to make sure that the values are unique.
Current code that gets this result:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
DropDownList1.Items.Add(item["shipCity"].Text);
}
}
I have not been able to find anything online and might just be googling the wrong question.
Just add additional check if item like this already exist:
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
if(DropDownList1.Items.FindByValue(item["shipCity"].Text) == null)
DropDownList1.Items.Add(item["shipCity"].Text);
}