在asp.net中使用绑定表达式时,如何连接文本? [英] How do you concatenate text when using Bind expression in asp.net

查看:164
本文介绍了在asp.net中使用绑定表达式时,如何连接文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将文本连接到asp.net网页(aspx)的绑定表达式中的语法是什么。

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" %>'

既没有

Text='<%# String.Concat(Bind("ID"), " View") %>'


推荐答案

如果使用模板字段,您还可以将连接放在标签的文本部分中:

You can also place the "concatenation" in the text portion of a tag if using a template field:

<asp:TemplateField HeaderText="Name" SortExpression="sortName">
<ItemTemplate>
   <asp:LinkButton ID="lbName" runat="server" OnClick="lbName_Click" CommandArgument='<%# Eval("ID") %>'>
         <%--Enter any text / eval bindind you want between the tags--%>
         <%# Eval("Name") %> (<%# Eval("ID") %>)
   </asp:LinkButton>
</ItemTemplate>

名称(ID)

在模板列内。

这篇关于在asp.net中使用绑定表达式时,如何连接文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆