简体   繁体   中英

Empty DataTextField property of DropDownList

I have a DropDownList that is bound to sqlDataSource . Part of the SQL query is:

"Select (firstName +" "+ SecondName +" "+ LastName) AS Name"

DataTextField property of the DropDownList is set to Name .

The problem is: if any of ( firstName , SecondName , and LastName ) equal to NULL , the DataTextField property become empty.

How can I fix this?

I use something like this. You have to check for NULL values and replace them with an empty string. Finally I replace 2 spaces with 1 in the replace function to account for empty SecondNames.

SELECT REPLACE(ISNULL(firstName, '') + ' ' + ISNULL(SecondName, '') + ' ' + ISNULL(LastName, ''), '  ', ' ') AS Name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM