在 DropDownList 中显示数据库中的更多列
如何在asp.net中的DropDownList中显示两列?
SqlDataSourceNamePeop.SelectCommand = "select name,forename from people";
DropDownListCaptain.DataTextField = "name";
像这样它只显示名称。但是我怎样才能显示名字+名字呢?
<asp:DropDownList ID="DropDownListPeople"
runat="server"
DataSourceID="SqlDataSourceNamePeop">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSourceNamePeop"
ConnectionString="xxxxx"
runat="server">
</asp:SqlDataSource>
How can I display two columns in the DropDownList in asp.net?
SqlDataSourceNamePeop.SelectCommand = "select name,forename from people";
DropDownListCaptain.DataTextField = "name";
Like this it displays only the names. But how can i display the names+forenames?
<asp:DropDownList ID="DropDownListPeople"
runat="server"
DataSourceID="SqlDataSourceNamePeop">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSourceNamePeop"
ConnectionString="xxxxx"
runat="server">
</asp:SqlDataSource>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
最简单的方法是像这样创建 sql 查询:
然后将此自定义属性绑定到下拉列表,如下所示:
让我知道它是否解决了您的问题,谢谢。
The easiest way is to make your sql query like this:
then bind this custom property to your drop down list like this:
Let me know if it fixed your problem, thanks.
将您的选择命令更改为
Change your select command to
检查 ** ** 零件
CHECK THE ** ** PARTS
它绝对有效。
it defiantly work.
下拉列表无法显示两个项目。你必须合并 trhem 然后将结果绑定到它。
请注意,还有一些其他下拉列表(基于 ajax 或简单)能够绑定到两个或更多列,但 ASP.net 无法处理它
Dropdownlist cannot display two items. you have to merge trhem and then bind the result to it.
note that there are some other dropdownlist (ajax based or simple ) which are able to bind to two or more columns, but ASP.net is not able to cope with it