asp:BoundField view the values with a condition

不想你离开。 提交于 2020-01-04 05:28:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!