Sunday 15 May 2011

c# - LINQ Query returning result set twice -


I am using this question to populate a drop down list on the asp.net page:
  

(Country RuleDataContact DB = New Census DataContext ()) {ddlCountry.Items.Clear (); Select ddlCountry.DataSource = c from db.CountryCodes in order c.CountryName c; DdlCountry.DataTextField = "Country Names"; DdlCountry.DataValueField = "Countrycode 1"; DdlCountry.AppendDataBoundItems = True; DdlCountry.DataBind (); Ddlcountry.Items.Instert (0, New ListItem ("- Select a Country -", "0")); }

The data source is a simple SQL table that has no duplicate. However, when my page render, the bound data is repeated twice in the drop down list control (AZA-Z).

What can anyone do, using specific () does not solve the problem (and there is no duplicate data in the table), and I have toList () at the end of my query Tried to add and it does not seem that it has to be fixed.

Regardless of the comments of Adam Maras and posting as an answer:

What does that mean Somewhere, later in the life cycle of the page, calling some ddlcountry.DataBind () , which controls the control to add the contents of the data source for the second time.

No comments:

Post a Comment