问题
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
回答1:
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>
回答2:
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.
来源:https://stackoverflow.com/questions/1839163/aspboundfield-view-the-values-with-a-condition