想要在绑定时在FormView Label项中添加条件 [英] Want to add a Condition in FormView Label item while binding

查看:48
本文介绍了想要在绑定时在FormView Label项中添加条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已从数据库whicc检索值,其中包括两个价格列,一个来自产品"表,一个来自"Store_Product"表.

因此,当将标签的文本与检索到的值绑定在一起时,我想将其设置为Store_Product.Price value,否则就必须设置 Product.Price value.我有:

I have retrieve values from database whicc consists of two price column in it one from "Product" and one from "Store_Product" tables.

So when binding a label''s text with the retrieved values, I want to set it to Store_Product.Price value if it is there otherwise I have to Set Product.Price value. I have:

<asp:Label ID="lblPrice" runat="server" Text='<%#Bind("price")>'%>

推荐答案

您绑定到的代码中的代码
(对象或数据集等)并将价格"设置为您想要的任何价格.

这是业务逻辑,不应该在您看来
I would do this in code inside what you are binding to
(an object, or data set etc) and set "price" to whatever price you want.

This is business logic and shouldn''t be in your view


您应该:
1)在代码中设置Price,该代码将使用您要使用的值填充数据库中的数据,并将其绑定.
2)在将两个对象绑定在一起的情况下,让price属性确定要显示的值.

无论哪种情况,您都可能会发现以下有用,尽管您必须对其进行调整:


You should either:
1) Set Price in the code that populates the data from the database with the value you want to use and bind it.
2) In the object you are binding two, have the price property work out which value to display.

in either case you might find the following useful, though you will have to adapt it:


decimal valueToUse = Store_Product.Price > 0 ? Store_Product.Price  : Product.Price;



假设您没有使用可为空的类型.



Assuming you haven''t used nullable types.


这篇关于想要在绑定时在FormView Label项中添加条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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