Hi,
When user selects a row in gridview i need to display the selected value in the dropdownlist.. The dropdownlits are populated at page load event... the selected value is getting displayed along with the value in the database.. How do get rid of duplicates?
Loading

Danish HabibPosted Apr 20, 2016, 8:12 AM
Vikram AgrawalPosted Dec 9, 2014, 5:39 AM
You can use DataView for get rid of duplicates.
DataView will filter records based on given condition
Karthik AgarwalPosted Jan 18, 2012, 4:58 AM
Dim list As New List(Of String)
If list.Contains("string") Then
//don't do anything
Else
list.Add("element")
End If
B M SuchitraPosted Jan 18, 2012, 3:09 AM
I have already explained it in my question but still for your understanding:
When user selects a row in gridview i need to display the selected value in the dropdownlist.. The dropdownlits are populated at page load event... the selected value is getting displayed along with the value in the database.. How do get rid of duplicates?
Datta KharadPosted Jan 18, 2012, 1:34 AM
Can you attach your example? or Describe your problem in detail...because I don't know exact problem which is facing you.
Abdullah MunshiPosted Jan 18, 2012, 12:20 AM
on GridviewSelectedIndexChanged event you can try something like,
DropdownList1.SelectedValue=Gridview1.SelectedRow.Cells[0].Text;
B M SuchitraPosted Jan 17, 2012, 11:19 PM
Same method i had got after i googled but that did not work for me so i came here and posted
Datta KharadPosted Jan 17, 2012, 5:27 AM
You can use below method to remove duplicate values from dropdownlist.
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;
}
}
}
}