ASP.NET Datalist 计算字段
我最近决定对我为乐趣而建立的电子商务网站征税,但我遇到了绊脚石。
我的实施效果很好,税收应用正确等,但是今天一位朋友向我指出,产品页面上的价格通常显示含税。
我在想,我可以在 DataList 本身上更改此设置,而不是编辑业务和数据层,但我一生都无法弄清楚如何实际做到这一点。我看过一些教科书并在网上进行了搜索,但因为我实际上不知道我在寻找什么,所以我陷入了困境:(。
数据列表:
<asp:DataList ID="list" runat="server" RepeatColumns="2" CssClass="ProductList" RepeatDirection="Horizontal"
Width="542px" EnableViewState="False" onitemcommand="list_ItemCommand">
<ItemTemplate>
<div style="width:271px;">
<h3 class="ProductName"><a href="<%# Link.ToProduct(Eval("ProductID").ToString()) %>"><%# HttpUtility.HtmlEncode(Eval("Name").ToString()) %></a></h3>
<a href="<%# Link.ToProduct(Eval("ProductID").ToString()) %>"><img width="100" border="0" src="<%# Link.ToProductImage(Eval("Thumbnail").ToString()) %>" alt='<%# HttpUtility.HtmlEncode(Eval("Name").ToString()) %>' /></a>
<%# HttpUtility.HtmlEncode(Eval("Description").ToString()) %>
<p>
<b>Price:</b>
<%# Eval("Price", "{0:c}") %>
</p>
<p>
<asp:Button ID="addToCartButton" runat="server" Text="Add to Basket" CommandArgument='<%# Eval("ProductID") %>' CssClass="SmallButtonText" />
</p>
</div>
</ItemTemplate>
</asp:DataList>
代码隐藏:
// Retrieve the list of products in a Sub Category
list.DataSource = CatalogAccess.GetProductsInSubCategory(subCategoryId, page, out howManyPages);
list.DataBind();
例如,如果数据库中的价格是 5 英镑,我需要将其在上面的数据列表中显示为 6 英镑,其中包括当前的英国 20% 增值税率,
因此: DBPrice * 1.2 = IncVatPrice
我希望这是有道理的!
提前致谢, 马特
I recently decided to implement tax on an ecommerce website I've built for fun more than anything and I've hit a stumbling block.
My implementation works well, tax is applied correctly etc, however a buddy pointed out to me today that prices on product pages are normally displayed inc tax.
I was thinking, rather than editing the Business and Data tier, I could change this on the DataList itself but I can't for the life of me work out how I'd actually do that. I've had a look in some text books and had a search around online but because I don't actually know what I'm looking for, I'm stuck :(.
Datalist:
<asp:DataList ID="list" runat="server" RepeatColumns="2" CssClass="ProductList" RepeatDirection="Horizontal"
Width="542px" EnableViewState="False" onitemcommand="list_ItemCommand">
<ItemTemplate>
<div style="width:271px;">
<h3 class="ProductName"><a href="<%# Link.ToProduct(Eval("ProductID").ToString()) %>"><%# HttpUtility.HtmlEncode(Eval("Name").ToString()) %></a></h3>
<a href="<%# Link.ToProduct(Eval("ProductID").ToString()) %>"><img width="100" border="0" src="<%# Link.ToProductImage(Eval("Thumbnail").ToString()) %>" alt='<%# HttpUtility.HtmlEncode(Eval("Name").ToString()) %>' /></a>
<%# HttpUtility.HtmlEncode(Eval("Description").ToString()) %>
<p>
<b>Price:</b>
<%# Eval("Price", "{0:c}") %>
</p>
<p>
<asp:Button ID="addToCartButton" runat="server" Text="Add to Basket" CommandArgument='<%# Eval("ProductID") %>' CssClass="SmallButtonText" />
</p>
</div>
</ItemTemplate>
</asp:DataList>
Code behind:
// Retrieve the list of products in a Sub Category
list.DataSource = CatalogAccess.GetProductsInSubCategory(subCategoryId, page, out howManyPages);
list.DataBind();
E.g. if the price in the DB is £5, I'd need it to be displayed in the datalist above as £6 which includes the current UK VAT rate of 20%.
So:
DBPrice * 1.2 = IncVatPrice
I hope this makes sense!
Thanks in advance,
Matt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
而不是
使用有点类似于的表达式
Or Implement a function in codebehind:
并在 DataList 中调用它,就像
http://www.pluralsight-training.net/community/blogs/fritz/archive/2005/12/16/17507.aspx
Instead of
use an expression somewhat similar to
Or implement a function in codebehind:
and call it in your DataList like that
http://www.pluralsight-training.net/community/blogs/fritz/archive/2005/12/16/17507.aspx