Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you concatenate text when using Bind expression in asp.net

What is the syntax to concatenate text into a binding expression for an asp.net webpage (aspx).

For example if I had a hyperlink that was being bound like this:

<asp:HyperLink id="lnkID" NavigateUrl='<%# Bind("Link") %>' Target="_blank" 
                        Text="View" runat="server"/>

How do you change, say, the Text to concatenate a bound value with a string? Variations like this aren't quite right.

Text='<%# Bind("ID") + " View" %>'

neither does

Text='<%# String.Concat(Bind("ID"), " View") %>'
like image 454
TheEmirOfGroofunkistan Avatar asked Dec 11 '08 20:12

TheEmirOfGroofunkistan


People also ask

How do you concatenate in C#?

You concatenate strings by using the + operator. For string literals and string constants, concatenation occurs at compile time; no run-time concatenation occurs. For string variables, concatenation occurs only at run time.

How do I concatenate strings in PowerShell?

In PowerShell, string concatenation is primarily achieved by using the “+” operator. There are also other ways like enclosing the strings inside double quotes, using a join operator, or using the -f operator. $str1="My name is vignesh."

What is binding in asp net?

The term 'data binding in ASP.NET simply means that the data that is collected from a source is bound to the controls that provide the read and write connection to the data. Databases, XML files, flat files, etc are some of the data sources we are talking about here.


1 Answers

Use Eval instead.

Text='<%# Eval("ID", "{0} View") %>'

Eval is also better if the value is not going to be updated, where Bind allows two way data binding.

like image 55
TheEmirOfGroofunkistan Avatar answered Sep 20 '22 14:09

TheEmirOfGroofunkistan