Gridview ItemTemplate 中多个 Eval 字段的最佳技术?

发布于 2024-07-05 04:27:14 字数 97 浏览 8 评论 0原文

在 GridView ItemTemplate 中使用多个 EVAL 字段的最佳方法是什么?

希望对外观格式以及设置超链接/javascript 等有一些控制。

What is the best way to use multiple EVAL fields in a GridView ItemTemplate?

Looking to have some control over formatting for appearance as well as setting up hyperlinks/javascript etc.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

原野 2024-07-12 04:27:14

Eval 和 Bind 都很糟糕。
为什么要通过反射来获取属性呢? 您可以像这样直接访问它:

((MyObject)Container.DataItem).MyProperty

这并不是说该对象在运行时对您来说是未知的。 无论如何,这是我的两分钱。

Eval and Bind both suck.
Why get the property through reflection? You can access it directly like this:

((MyObject)Container.DataItem).MyProperty

It's not like the object is unknown to you at runtime. That's my two cents, anyhow.

哎呦我呸! 2024-07-12 04:27:14

我以前使用过这个(不好,我知道):

<%# Eval("Name1", "{0} - ")%> <%#Eval("Name2")%>

Result = 'John - Smith'

但刚刚发现我也可以将两个(或更多)Evals 放在同一个数据绑定组中:

<%#Eval("Name1") & " - " & Eval("Name2")%>

Result = 'John - Smith'

<%# "First Name - " & Eval("Name1") & ", Last Name - " & Eval("Name2")%>  

Result = '名字 - 约翰,姓氏 - 史密斯'

I had previously used this (bad, I know):

<%# Eval("Name1", "{0} - ")%> <%#Eval("Name2")%>

Result = 'John - Smith'

But just discovered that I can also put TWO (or more) Evals in the same data-bound group:

<%#Eval("Name1") & " - " & Eval("Name2")%>

Result = 'John - Smith'

Or

<%# "First Name - " & Eval("Name1") & ", Last Name - " & Eval("Name2")%>  

Result = 'First Name - John, Last Name - Smith'

烟雨扶苏 2024-07-12 04:27:14

IMO 更清楚的是:

<%# String.Format("{0} - {1}", Eval("Name1"), Eval("Name2")) %>

Even clearer, IMO, is:

<%# String.Format("{0} - {1}", Eval("Name1"), Eval("Name2")) %>
微暖i 2024-07-12 04:27:14

我有一个最简单的方法来做同样的事情

<asp:Label ID="lblName" runat="server" Text='<%#Eval("FirstName").ToString() +", "+ Eval("LastName").ToString() %>'></asp:Label>

......

<%#Eval("FirstName").ToString() +", "+ Eval("LastName").ToString() %>

这里两个对象都被转换为字符串并将它们连接起来。

I have a easiest way to do this same thing...

<asp:Label ID="lblName" runat="server" Text='<%#Eval("FirstName").ToString() +", "+ Eval("LastName").ToString() %>'></asp:Label>

.

<%#Eval("FirstName").ToString() +", "+ Eval("LastName").ToString() %>

Here both objects are converted into string the concatenate them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文