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


Datta KharadRank #2,135 · 668 reputationPosted Jan 17, 2012, 12:27 AM EST
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;
}
}
}
}
B M SuchitraRank #2,922 · 492 reputationPosted Jan 17, 2012, 6:19 PM EST
Same method i had got after i googled but that did not work for me so i came here and posted
Abdullah Munshi51 reputationPosted Jan 17, 2012, 7:20 PM EST
on GridviewSelectedIndexChanged event you can try something like,
DropdownList1.SelectedValue=Gridview1.SelectedRow.Cells[0].Text;
Datta KharadRank #2,135 · 668 reputationPosted Jan 17, 2012, 8:34 PM EST
Can you attach your example? or Describe your problem in detail...because I don't know exact problem which is facing you.
B M SuchitraRank #2,922 · 492 reputationPosted Jan 17, 2012, 10:09 PM EST
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?
Karthik AgarwalRank #2,270 · 620 reputationPosted Jan 17, 2012, 11:58 PM EST
Dim list As New List(Of String)
If list.Contains("string") Then
//don't do anything
Else
list.Add("element")
End If
Vikram AgrawalRank #4,713 · 329 reputationPosted Dec 9, 2014, 12:39 AM EST
You can use DataView for get rid of duplicates.
DataView will filter records based on given condition
Danish HabibRank #2,024 · 715 reputationPosted Apr 20, 2016, 4:12 AM EDT