Reputation: 4443
I want to put on DataTextField
more than 1 item from database (surname and name). How can I do this?
Of course, DataTextField="surname + name"
doesn't work, but is there any possibility to put together this 2 items?
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:
public static DataSet getAllSpecialist()
{
sql = "select * from tuserspecialist where del='false' and name!=''";
return SQLTools.getDataSet(sql);
}
Upvotes: 0
Views: 1118
Reputation: 1879
You could do something like
SELECT name + ' ' + surname AS Fullname FROM tuserspecialist WHERE del='false' AND name!=''"
and then set DataTextField="Fullname";
Upvotes: 0
Reputation: 103378
Change your SQL statement:
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"
Upvotes: 3