0

以下事件处理程序正在返回它的列表,但它并不明显。列表中仍有许多重复项。有什么想法吗?

Protected Sub ddlState_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlState.SelectedIndexChanged
    If IsPostBack Then
        ddlCity.Items.Clear()
        Dim context As New teckEntities()
        Using context
            'Dim query = From c In context.counties Where c.stateid = ddlState.SelectedValue Select c.countyname, c.id
            Dim query = From c In context.ziptaxes Where c.StateID = ddlState.SelectedValue Order By c.City Select c.City, c.ZipTaxId
            query.Distinct()
            ddlCity.DataSource = query.ToList()
            ddlCity.DataValueField = "ziptaxid"
            ddlCity.DataTextField = "City"
            ddlCity.DataBind()
        End Using
    End If

End Sub
4

1 回答 1

0

您应该在应用distinct过滤器后分配查询的返回值。

 ddlCity.DataSource = query.Distinct().ToList()
 ddlCity.DataValueField = "ziptaxid"
 ddlCity.DataTextField = "City"
 ddlCity.DataBind()
于 2012-09-09T15:42:11.217 回答