且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

连接内联代码ASP.NET中的两个或多个字符串

更新时间:2023-02-17 10:30:53

如果您要限制使用内联代码可以轻松处理的内容的限制,则可以始终编写一个函数.然后,您可以执行以下操作:

If you're pushing the limits of what you can easily handle with inline code, you could always write a function instead. Then you can do something like:

 <asp:Label ID="lblOne" runat="server"   Text= '<%# EmitSomeText(Eval("name"), Eval("StatusId"), Eval("assignfilename")) %>' />

这使您可以将一个复杂的表达式分成任意多行,这可能会少一些麻烦.您可以在CodeBehind或任何其他类中使用函数.

This lets you break a complex expression up into however many lines it needs to be, which can be a little less awkward. You can use a function in your CodeBehind or any other class.

如果绑定到您有权访问的类,则可以添加一个只读属性.然后,您可以执行类似Eval("MyNewProperty")的操作.

If you're binding to a class that you have access to, you could add a readonly property. Then you can do something like Eval("MyNewProperty").

我使用它来公开需要重用的格式.例如,Customer.CustomerFullName可能返回以逗号分隔的姓氏(以智能方式处理其中一个或另一个或两者都不存在的情况)以及可选标题,因为我的客户是医学界人士,并且其中一些人拥有博士学位和医学博士学位.

I use that for exposing formatting that I need to re-use. For instance, Customer.CustomerFullName might return last name first seperated be a comma (intelligently handling situations where one or the other or both are missing) plus an optional title, since maybe my customers are medical folks and some of them have PhDs and MDs.