需要有关DataList中的Eval的帮助 [英] Need help with Eval inside DataList

查看:108
本文介绍了需要有关DataList中的Eval的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该足够简单,我主要将此归咎于我在使用DataList,Repeaters等方面的经验不足。

This should be simple enough, and I blame this primarily on my inexperience working with DataLists, Repeaters, etc.

我有一个DataList控件,我正在使用该控件显示购物车中的物品。通过使用Eval( ColumnName)绑定不同的控件,一切都进行得很好,直到到达价格列为止。

I have a DataList control which I am using to display the items in a shopping cart. Everything is going along fine with my binding of the different controls using Eval("ColumnName") until I get to the price column.

我的目标是像这样渲染它:

My goal is to render it like so:


项目总成本



$ 20.00
(每个$ 5.00)

Total Item Cost

$20.00 ($5.00 each)

我试图通过在表格单元格内使用两个ASP Label控件来实现此目的:

I am trying to accomplish this with two ASP Label controls inside the table cell:

<asp:Label ID="lblTotalItemCost" runat="server" Text='<%# Eval("TotalItemCost") %>'>
</asp:Label>
<br />
<asp:Label ID="lblPrice" runat="server" Text='(<%# Eval("Price")%> each)' >
</asp:Label>

不幸的是,它将列显示为:

Unfortunately it is rendering out the column as:


项目总成本



$ 20.00
(每个<%#Eval( Price)%>)

Total Item Cost

$20.00 (<%# Eval("Price")%> each)

我尝试了几种其他方法,但最终给了我服务器标签格式不正确的错误。我很确定这应该很简单,但此刻我很困惑。

I've tried a couple other methods, but they end up giving me "server tag not well formed" errors. I am pretty sure this should be simple but I'm stumped at the moment.

推荐答案

请尝试以下操作:

Text='<%#"(" + Eval("Price").ToString() + " each)"%>'

这篇关于需要有关DataList中的Eval的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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