asp:BoundField 查看带条件的值

发布于 2024-08-13 04:00:37 字数 336 浏览 5 评论 0原文

我有一个数据视图:

<asp:BoundField DataField="AccontoAutorizzato" HeaderText="Acconto Aut." 
                        SortExpression="AccontoAutorizzato" dataformatstring="{0:C}"  />

是否可以隐藏每个条件的值,例如

 Visible=<%# ((Int32)Eval("StatoID") < 2) %>

谢谢

i have a dataview with:

<asp:BoundField DataField="AccontoAutorizzato" HeaderText="Acconto Aut." 
                        SortExpression="AccontoAutorizzato" dataformatstring="{0:C}"  />

is possible hide the values of each with a condition like

 Visible=<%# ((Int32)Eval("StatoID") < 2) %>

?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

念三年u 2024-08-20 04:00:37

可以通过以下方式

<asp:TemplateField HeaderText="Acconto Aut." >
     <ItemTemplate>
          <asp:Label ID="lbl" runat="server" Text='<%# Bind("AccontoAutorizzato") %>'
                        Visible='<%# ((int)(Eval("StatoID")) < 2) %>' />
     </ItemTemplate>
</asp:TemplateField>

It's possible with following

<asp:TemplateField HeaderText="Acconto Aut." >
     <ItemTemplate>
          <asp:Label ID="lbl" runat="server" Text='<%# Bind("AccontoAutorizzato") %>'
                        Visible='<%# ((int)(Eval("StatoID")) < 2) %>' />
     </ItemTemplate>
</asp:TemplateField>
感情废物 2024-08-20 04:00:37

Saar 的回答 对我不起作用,因为即使绑定应该返回 true 或 false,解释器实际上也无法将条件结果转换为布尔值。

因此,我使用了明确选择的布尔值:

<asp:TemplateField HeaderText="Acconto Aut." >
     <ItemTemplate>
          <asp:Label ID="lbl" runat="server" Text='<%# Bind"AccontoAutorizzato") %>'
                        Visible='<%# ((int)(Eval("StatoID")) < 2) ? Convert.ToBoolean(0) : Convert.ToBoolean(1) %>' />
     </ItemTemplate>
</asp:TemplateField>

我希望这可以让其他人在将其应用于可见属性时更容易遇到布尔错误。

Saar's answer did not work for me, because even though the binding should return a true or false, the interpreter could not actually convert the condition result to a Boolean value.

So instead, I used an explicit choice of Boolean values:

<asp:TemplateField HeaderText="Acconto Aut." >
     <ItemTemplate>
          <asp:Label ID="lbl" runat="server" Text='<%# Bind"AccontoAutorizzato") %>'
                        Visible='<%# ((int)(Eval("StatoID")) < 2) ? Convert.ToBoolean(0) : Convert.ToBoolean(1) %>' />
     </ItemTemplate>
</asp:TemplateField>

I hope this makes it easier for others struggling with the Boolean error when applying it to a Visible property.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文