Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

How to Concatinate String for DataTextField of DropDowns

  Asked By: Sienna    Date: Sep 26    Category: Asp.net    Views: 917
  


Dim Conn As Object ' SqlConnection
Dim Comm As Object ' SqlCommand
Dim dataRdr As SqlDataReader
Dim Sqwl As String

InitializeDBObjects(Conn, Comm)'This is a
Function to set the Connection and the
'Command Object
Comm.Connection = Conn


Try
Conn.Open()
Catch
Exit Function
End Try

Sqwl = "select * from library_Author "
Comm.CommandText = Sqwl
DrpDwnCategory.DataSource =
Comm.ExecuteReader()
DrpDwnCategory.DataBind()
Conn.close()
Comm.dispose()


The Problem is that I have got the Author
FName(FirstName) and the LName(LastName) in the
DataTextField I want to concatinate Both the Fields
and present it,How Do I do this
I cant do it in the HTML Part as it throws Error and
if I do it in the Code behind How do
I do it.

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Aaron Kennedy     Answered On: Sep 26

Firstly dont use a * in your select  statment, this is very bad practice for
several reasons, but to do what you want do...

select FName + ' ' + LName as fullname from library_Author

(Along with any other columns that you require)

 
Answer #2    Answered By: Ana Silva     Answered On: Sep 26

Since there were only 3 Fields I used *
But then as you said Its a Bad Practise thanx a Lot
for the Solution.

 
Answer #3    Answered By: Dustin Dean     Answered On: Sep 26

Once other thing you are probably best doing as well is using the IsNull
operator, any nulls in either column will make the whole statement return a
null (A NULL + a string  always = NULL)...

select IsNull(FName, '') + ' ' + IsNull(LName, '') as fullname

That is assuming you are using MS SQL?

 
Answer #4    Answered By: Ruairidh Anderson     Answered On: Sep 26

Yes I am using SqlServer.Ya will follow this !!

 
Didn't find what you were looking for? Find more on How to Concatinate String for DataTextField of DropDowns Or get search suggestion and latest updates.