How to concatenate static text in the start of Eval("") in asp.net?
            Asked
            
        
        
            Active
            
        
            Viewed 8.4k times
        
    33
            
            
         
    
    
        Carlos Muñoz
        
- 17,397
- 7
- 55
- 80
 
    
    
        israr
        
- 331
- 1
- 3
- 3
6 Answers
64
            
            
        try...
Text='<%# "Mr " + Eval("FirstName") + " " + Eval("LastName")%>'
 
    
    
        Muhammad Akhtar
        
- 51,913
- 37
- 138
- 191
- 
                    I got a string-to-double conversion error when I did this, but it worked after I changed the first '+' to '&'. – Resource Dec 04 '15 at 12:24
- 
                    @user910683 I'm guessing you were using VB (not C#) in which yes, to more reliably concatenate values into a string, you should use `&` -- http://stackoverflow.com/questions/734600/the-difference-between-and-for-joining-strings-in-vb-net – Don Cheadle Feb 18 '16 at 18:23
20
            
            
        For concating two fields from db you can use string.Concat function in eval()
 Text='<%# string.Concat(Eval("FirstName"), " ", Eval("LastName"))%>'
 
    
    
        Tarun Gupta
        
- 6,305
- 2
- 42
- 39
0
            
            
        Doing this (without single quote) worked for me. And Visual Studio underlines it as a Validation warning.
 onclick=<%# "modCbClick('#tbl_" + Eval("ModCode") + "', this)" %>
 
    
    
        Kenz Mitnick
        
- 11
- 1
0
            
            
        Here is a good method I am using whereby I want to Concatenate a string to an Eval and use in the CommandArgument of a LinkButton.
Append string to start
CommandArgument='<%# String.Format(string.Concat("TextString", Eval("DBValue")))%>'
Append string to end
CommandArgument='<%# String.Format(string.Concat(Eval("DBValue"), "TextString"))%>'
 
    
    
        Stephen85
        
- 250
- 1
- 15
 
     
    