dropdownlist DataTextField property

Using an asp:DropDownList control on a webform.  The databound has id, lastname, firstname fields, but no fullname  (lastname + ', ' + firstname).  I need the fullname however I am not allowed to alter the sql query to return the fullname...so I think I need to find an alternative to the datatextfield.  
<asp:DropDownList ID="ddlFullName" runat="server"  DataTextField="???" DataValueField="ID"></asp:DropDownList>

Open in new window

MariaHaltAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MlandaTCommented:
you may need to change from using the databinding approach to manually adding items to the list. Something like this:

                    For i As Integer = 0 To ds.Tables(0).Rows.Count - 1

                        Dim dr As DataRow = ds.Tables(0).Rows(i)

                        Dim itm As New ListItem(dr("ID"), dr("Firstname") + " " + dr("LastName"))

                        myCombo.Items.Add(itm)

                    Next
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ramkihardyCommented:
Declare a variable named Full Name
String Fullname="";
Exceute the query and get the query in sqldatareader
if(dr.HasRows)
{
while(dr.Read())
{
Fullname=dr["FirstName"].toString() +' '+dr["Lastname"].ToString();
}
}

Then the Fullname variable has the full name of the candidate....
If u want further help ask me...
Regards
Ramki....
0
MariaHaltAuthor Commented:
Although I think both solutions above will work, we must use strongly typed code and found my solution here, http://www.ipreferjim.com/site/2009/04/displaying-multiple-fields-in-a-dropdownlists-datatextfield/.  

Basically,

ddlUsers.DataSource = BLL.Employee.GetEmployees()  

2                 .Select(be =>  

3                     new {  

4                         ID = be.Id,  

5                         FullName = String.Format("{0}{1}{2}",  

6                                     be.LastName,  

7                                     (!string.IsNullOrEmpty(be.FirstName) ? ", " : string.Empty),  

8                                     be.FirstName)  

9                         }).AsEnumerable();
0
MariaHaltAuthor Commented:
I'm accepting my solution b/c it works for strongly typed code and may someday help others faced with the same problem.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.