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
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 685
1 Manas Bhardwaj 380
2 OriginalGriff 344
3 Abhinav S 293
4 Sampath Lokuge 245
0 Sergey Alexandrovich Kryukov 7,967
1 OriginalGriff 4,332
2 Peter Leow 3,699
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


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