增值数据绑定DROPDOWNLIST(asp.net) [英] Adding Value to databound DropDownlist (asp.net)
问题描述
我创建一个网站,该网站拥有1 DropDownList的那势必Northwind数据库,客户表。这种下降downlist将列出所有从表中的国家。我曾经试图日本(这是不是在列表中)添加到该DropDownList中。它补充,但它总是出现在顶部(或默认值)。我的问题是:是否有可能增加日本和不能让它出现在顶部,因此它会按照字母顺序
这是我的code:
< ASP:DropDownList的ID =DropDownList1=服务器AppendDataBoundItems =真
的AutoPostBack =真的DataSourceID =SqlDataSource1DataTextField =国家
DataValueField =国家>< ASP:ListItem的文本=日本/>
< / ASP:DropDownList的>
< ASP:SqlDataSource的ID =SqlDataSource1=服务器
的ConnectionString =下;%$的ConnectionStrings:NorthwindConnectionString2%>中 的SelectCommand =选择国家客户的GROUP BY国家ORDER BY国家>
< / ASP:SqlDataSource的>
您可以尝试在你的SQL脚本这样。
选择国家
从
(
选择国家
客户
GROUP BY国家 UNION ALL 选择JAPAN
)M
ORDER BY国家
I am creating a website which has 1 dropdownlist that bound to Northwind database, Customers table. This Drop downlist will list all the countries from the tables. I have tried to add "Japan" (which was not in the list) to this dropdownlist. It was added but it always appear at the top (or default value). My question is: Is it possible to add Japan and not make it appear at the top, so it will follow the alphabetical order?
This is my code:
<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>
You can try this way in your sql script.
SELECT Country
FROM
(
SELECT Country
FROM Customers
GROUP BY Country
UNION ALL
SELECT 'JAPAN'
) M
ORDER BY Country
这篇关于增值数据绑定DROPDOWNLIST(asp.net)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!