开发者

conditional markup in control's template

开发者 https://www.devze.com 2023-02-21 20:46 出处:网络
I have a repeater control on my .aspx page. There are times where a product is unique, so you can\'t change it\'s quantity, but in other cases when there are lots of items of this product, you should

I have a repeater control on my .aspx page. There are times where a product is unique, so you can't change it's quantity, but in other cases when there are lots of items of this product, you should be able to edit it's quantity using a textbox and a linkbutton. Both OnlyOne and Quantity are present in the binded collection classes. I need to check the OnlyOne condition, something like that:

                    <%开发者_如何学编程 if (OnlyOne) { %>
                        <%# Eval("Quantity") %>
                        <%} else { %>
                        <asp:TextBox ID="TextBox1" runat="server" />
                        <asp:LinkButton ID="LinkButton1" runat="server">OK</asp:LinkButton>
                        <% }%>

The problem is that ASP.NET doesn't find the OnlyOne field. I've tried also (bool)Eval("OnlyOne"), but that didn't work also. So how should I write the condition?


Done it like that:

<asp:Label Text='<%# Eval("Quantity") %>' runat="server" ID="QuantityLabel" Visible='<%# Eval("OnlyOne") %>' />
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("Quantity") %>' Visible='<%# !(bool)Eval("OnlyOne") %>' />
<asp:LinkButton ID="LinkButton1" runat="server"  Visible='<%# !(bool)Eval("OnlyOne") %>' Text="OK" />

But I am still interested to hear the answer :) .

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号