如何在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>
答案 0 :(得分:3)
最简单的方法是进行这样的SQL查询:
SqlDataSourceNameJuc.SelectCommand = "select name + ' ' +forename as FullName from people";
然后将此自定义属性绑定到下拉列表,如下所示:
DropDownListCaptain.DataTextField = "FullName";
让我知道它是否解决了你的问题,谢谢。
答案 1 :(得分:1)
将您的选择命令更改为
"Select name + ',' + forename as 'name' from people"
答案 2 :(得分:0)
<asp:DropDownList ID="DropDownList9" runat="server"
DataSourceID="SqlDataSource3" DataTextField="**CALL_NAMESURNAME**"
DataValueField="CALL_NAME">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:McCarthyConnectionString %>"
SelectCommand="SELECT [CALL_NAME], [SURNAME],**CALL_NAME + SURNAME AS [CALL_NAMESURNAME]** FROM [Sheet1$] where COY_NAME LIKE '%abc%'">
</asp:SqlDataSource>
检查** **部件
答案 3 :(得分:0)
IList<PM_ClientInformation> objPM_ClientInformation = new List<PM_ClientInformation>();
//get information in objPM_ClientInformation
foreach (PM_ClientInformation f in objPM_ClientInformation)
{
string text = string.Format("{0}{1}",
f.PM_cliFirstName.PadRight(10,'\u00A0'),
f.PM_cliLastName.PadRight(10,'\u00A0'));
ddlClientName.Items.Add(new ListItem (text ,f.PM_cliId.ToString()));
}
它非常有效。
答案 4 :(得分:-1)
Dropdownlist无法显示两个项目。你必须合并trhem,然后将结果绑定到它。
请注意,还有一些其他下拉列表(基于ajax或简单)可以绑定到两个或更多列,但ASP.net无法应对它