Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

We need to bind a webservice result into a dropdownlist,but the problem is duplicate countryname is binding.

Actually the webservice SOAP O/P contains 80 values in which duplicates are there.We need to avoid teh duplication using LINQ query.

The query to bind the dropdownlist using webservice is below.

VB
myICTCReceCountry = myICTCWebService.GetReceivingCountry(myICTCRecCountrySOAPIn).Records

               For i As Integer = 0 To myICTCReceCountry.Length - 1
                   'ddlCountry.DataTextField = myICTCReceCountry(i).Country_Name
                   'ddlCountry.DataValueField = myICTCReceCountry(i).Destination_Country
                   ddlCountry.Items.Insert(i, New ListItem(myICTCReceCountry(i).Country_Name, myICTCReceCountry(i).Destination_Country))
               Next



Please help

Regards
Sreejith
Posted
Comments
Maciej Los 7-May-15 2:21am    
What returns myICTCWebService.GetReceivingCountry(myICTCRecCountrySOAPIn).Records? Please, be more specific and provide more details.

VB
Dim lst = From a In myICTCReceCountry_
          Order By a_
          Select New With {Key a.Country_Name, a.Destination_Country}Distinct.ToList

      For Each lr In lst  
              ddlCountry.DataTextField = lr.Country_Name;
                ddlCountry.DataValueField = lr.Destination_Country;
      Next
 
Share this answer
 
v2
Comments
Member 11658469 7-May-15 2:53am    
Hi Thanks for the reply.

We are doing the code in vb.net.So when we convert the code and copy into our application like

Dim lstResult As string() = (From a In myICTCReceCountry With{Key.Country_Name = a.Country_Name,Key.Destination_Country = a.Destination_Country}).ToList.Distinct()
For Each lst As String In lstResult
ddlCountry.DataTextField = lst.Country_Name
ddlCountry.DataValueField = lst.Destination_Country
Next
We facing an error in the With & lstResult variable.Please help
As per my understanding, you want to get non-duplicated values. So, you need to use Group By Clause[^] or Distinct method[^] values ;)

For further information, please see:
How to: Count, Sum, or Average Data by Using LINQ (Visual Basic)[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900