Label项中添加条件

Label项中添加条件

本文介绍了想要在绑定时在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")>'%>

推荐答案


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



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



Assuming you haven''t used nullable types.


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

08-16 01:19