M
Mark Rae
Hi,
Here's one just for my own interest - I know how to add ListItems
programatically, and how to concatenate fields in SQL queries...
But, is there any way to specify anything other than a single database field
in the DataTextField of a DropDownList?
E.g. let's say I have the following SQL Server table called MyUsers:
UserID FirstName LastName
----------------------------------
1 Juan Libre
2 Peter Bromberg
3 John Timney
4 Mark Rae
And I populate my DropDownList like this:
string strSQL = "SELECT UserID, FirstName, LastName FROM MyUsers";
using (SqlDataReader MyReader = GetSqlDataReader(strSQL)
{
cmbUsers.DataSource = MyReader;
cmbUsers.DataValueField = "UserID";
cmbUsers.DataTextField = "LastName";
cmbUsers.DataBind();
}
But is there any way (other than adding the ListItems manually or changing
the SQL) to persuade the DataTextField to concatenate the LastName and
FirstName fields so that it displays:
Libre, Juan
Bromberg, Peter
Timney, John
Rae, Mark
As I mentioned, just for my own interest...
Any assistance gratefully received.
Mark
Here's one just for my own interest - I know how to add ListItems
programatically, and how to concatenate fields in SQL queries...
But, is there any way to specify anything other than a single database field
in the DataTextField of a DropDownList?
E.g. let's say I have the following SQL Server table called MyUsers:
UserID FirstName LastName
----------------------------------
1 Juan Libre
2 Peter Bromberg
3 John Timney
4 Mark Rae
And I populate my DropDownList like this:
string strSQL = "SELECT UserID, FirstName, LastName FROM MyUsers";
using (SqlDataReader MyReader = GetSqlDataReader(strSQL)
{
cmbUsers.DataSource = MyReader;
cmbUsers.DataValueField = "UserID";
cmbUsers.DataTextField = "LastName";
cmbUsers.DataBind();
}
But is there any way (other than adding the ListItems manually or changing
the SQL) to persuade the DataTextField to concatenate the LastName and
FirstName fields so that it displays:
Libre, Juan
Bromberg, Peter
Timney, John
Rae, Mark
As I mentioned, just for my own interest...
Any assistance gratefully received.
Mark