2012-04-10 59 views
1

我在一個頁面上有十個DropDownList。當我爲所有人使用相同的數據源時,所有十個值都有重複值。是否有一種方法可以爲所有十個DropDownList使用一個SqlDataSource,並且只爲每個DropDownList獲取不同的值。來自一個SqlDataSource的DropDownList的不同值

這是一個例子下拉列表和SqlDataSource的:

<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="County" DataValueField="County"AppendDataBoundItems="true"></asp:DropDownList> 


<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings %>" 
    SelectCommand="SELECT Distinct * FROM [Personal]"></asp:SqlDataSource> 

在此先感謝

+0

是否每個下拉列表有不同的DataTextField和DataValueField界定? – JCherryhomes 2012-04-10 02:20:21

+0

是的每個dropDownList將有不同的DataTextField和DataValueField,謝謝 – user973671 2012-04-10 02:29:41

回答

0

我懷疑你的SQL查詢,因爲你正在使用SELECT *返回受騙者。如果表中有與其他字段不同的字段的任何記錄,例如自動增量主鍵,則也會返回這些記錄。獨特確保整個記錄集是唯一的。

嘗試限制您的查詢僅限於您需要的字段。

SELECT Distinct County FROM [Personal] 

檢查此鏈接:http://www.w3schools.com/sql/sql_distinct.asp

+0

備用我的w3fools鏈接... – Darthg8r 2012-04-10 02:32:25

+0

在這種情況下,我需要爲每個DropDownList使用不同的SqlDataSource。感謝雖然。 – user973671 2012-04-10 02:35:34