How to concatenate static text in the start of Eval("") in asp.net?
Asked
Active
Viewed 8.0k times
33
Carlos Muñoz
- 16,721
- 7
- 55
- 78
israr
- 331
- 1
- 3
- 3
6 Answers
64
try...
Text='<%# "Mr " + Eval("FirstName") + " " + Eval("LastName")%>'
Muhammad Akhtar
- 51,472
- 37
- 135
- 186
-
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
18
For concating two fields from db you can use string.Concat function in eval()
Text='<%# string.Concat(Eval("FirstName"), " ", Eval("LastName"))%>'
Tarun Gupta
- 6,137
- 2
- 38
- 38
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
- 238
- 1
- 14