2012-02-23 58 views
1

我正在創建一個網站,其中有1個dropdownlist綁定到Northwind數據庫Customers表。此下拉列表將列出表格中的所有國家/地區。我試圖將「日本」(不在列表中)添加到此下拉列表中。它已被添加,但始終顯示在頂部(或默認值)。我的問題是:是否可以添加日本,而不是讓它出現在頂部,所以它會按照字母順序?爲數據綁定添加價值DropDownlist(asp.net)

這是我的代碼:

<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True" 
      AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="Country" 
      DataValueField="Country"><asp:ListItem Text ="Japan" /> 
     </asp:DropDownList> 
     <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
      ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString2 %>" 

      SelectCommand="SELECT Country FROM Customers GROUP BY Country ORDER BY Country"> 
     </asp:SqlDataSource> 

回答

2

你可以試試這個方法在sql腳本。

SELECT Country 
FROM 
(
    SELECT Country 
    FROM Customers 
    GROUP BY Country 

    UNION ALL 

    SELECT 'JAPAN' 
) M 
ORDER BY Country 
+0

太感謝你了,這正是我一直在尋找 – 2012-02-23 02:03:42

+0

請接受,如果該解決方案是正確的,你很高興.. – 2012-02-23 02:06:42

相關問題