Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
good evening,
 
when i am binding dropdown to the database, one dropdownlist item repeats two times.
 
please help me.
 
thank you.
Posted 27-Feb-13 0:25am
Comments
kishore Rajendran at 27-Feb-13 6:37am
   
please post your code
Member 9567873 at 27-Feb-13 6:55am
   
this is my code
 
public void DropDownFill()
{
ItemManagementDetails itemDetails = new ItemManagementDetails();
ListItemForDropDown list = new ListItemForDropDown();
InventoryClient objService = new InventoryClient();
 
list = objService.FillDropDownStore();
list.List.RemoveAt(0);
ddlStoreId.DataSource = list.List.OrderBy(x => x.Text);
ddlStoreId.DataBind();
ddlStoreId.Items.Insert(0, "--Select --");
 
}
Member 9567873 at 27-Feb-13 6:59am
   
I have posted the code please see the code and please help me
Matej Hlatky at 27-Feb-13 7:03am
   
Have you tried to use DISTINCT statement / Distinct() Linq extension method?
Member 9567873 at 27-Feb-13 7:08am
   
no i have not used please tell me how to use it
Matej Hlatky at 27-Feb-13 7:09am
   
Just add Distinct() at the end of your linq methods: ddlStoreId.DataSource = list.List.OrderBy(x => x.Text).Distinct();
Member 9567873 at 27-Feb-13 7:15am
   
i have added .Distinct() but it is not working.
Rai Pawan at 27-Feb-13 7:19am
   
It pretty much seems to be the case where your method titled DropDownFill is being called twice. Probably at page_load event and on some other event. Try to debug the method, check whether it is getting called twice.
-Pawan
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Check what your query returns, maybe its in there 2 times
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

there is some issue in your code check it painfully, otherwise following code you can use.
this.drpDown.Clear();
this.drpDown.DataSource = dt;
this.drpDown.DataBinding();
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 307
1 Nirav Prabtani 268
2 Sergey Alexandrovich Kryukov 182
3 _Amy 170
4 Mika Wendelius 165
0 Nirav Prabtani 284
1 OriginalGriff 207
2 _Amy 170
3 Mika Wendelius 165
4 Sergey Alexandrovich Kryukov 119


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 27 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100