[英]DropDownList - more than 1 item on DataTextField
I want to put on DataTextField
more than 1 item from database (surname and name). 我想从数据库(姓氏和名称)中放入
DataTextField
多个项目。 How can I do this? 我怎样才能做到这一点?
Of course, DataTextField="surname + name"
doesn't work, but is there any possibility to put together this 2 items? 当然,
DataTextField="surname + name"
不起作用,但是是否有可能将这两个项目放在一起?
There is my code: 有我的代码:
<asp:DropDownList runat="server" ID="dllSpecialist" DataValueField="iduserspecialist" DataTextField="surname" AutoPostBack="true" OnSelectedIndexChanged="dllSpecialist_IndexChanged" AppendDataBoundItems="true">
<asp:ListItem Text="" Value="0"></asp:ListItem>
</asp:DropDownList>
code behind: 后面的代码:
if (!IsPostBack)
{
dllSpecialist.DataSource = tUserSpecialistBO.getAllSpecialist();
dllSpecialist.DataBind();
(..)
}
sql method: sql方法:
public static DataSet getAllSpecialist()
{
sql = "select * from tuserspecialist where del='false' and name!=''";
return SQLTools.getDataSet(sql);
}
Change your SQL statement: 更改您的SQL语句:
sql = "select surname + ' ' + name as FullName, iduserspecialist from tuserspecialist where del='false' and name!=''";
Then change your property to specify the new data item: 然后更改您的属性以指定新的数据项:
DataTextField="FullName"
You could do something like 你可以做类似的事情
SELECT name + ' ' + surname AS Fullname FROM tuserspecialist WHERE del='false' AND name!=''"
and then set DataTextField="Fullname";
然后设置
DataTextField="Fullname";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.