vb.net 如果边界字段的网格视图条件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16319026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 13:26:50  来源:igfitidea点击:

If condition on a gridview for boundfield?

.netvb.netgridviewboundfield

提问by software

I have a gridview with the following boundfiled. DataField is decimal value. If the value is anything higher than 0 I want to display as True in grdiview else false. How to do , if conditon for the boundfileld . can anyone help. I can use TemplateField if that gives the solution.

我有一个具有以下边界的网格视图。DataField 是十进制值。如果该值高于 0,我想在 grdiview 中显示为 True,否则为 false。如果 boundfileld 的条件成立,该怎么办。任何人都可以帮忙。如果提供解决方案,我可以使用 TemplateField。

<asp:BoundField HeaderText="fieldone" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left"
    DataField="Higher" NullDisplayText="0">
    <HeaderStyle HorizontalAlign="Left"></HeaderStyle>
    <ItemStyle HorizontalAlign="Left"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="fieldtwo" Rebate" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left"
    DataField="Lower" NullDisplayText="0">
    <HeaderStyle HorizontalAlign="Left"></HeaderStyle>
    <ItemStyle HorizontalAlign="Left"></ItemStyle>
</asp:BoundField>

回答by Zo Has

You can use a templatefield & drop a label control inside it. Something like

您可以使用模板字段并在其中放置一个标签控件。就像是

<asp:TemplateField>
                <ItemTemplate>
                    <asp:Label ID="lblStatus" runat="server" Text='<%# (Convert.ToDecimal(Eval("UnitPrice")) > 0) ? "True" : "False"   %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>

Alternatively, you can also use RowDataBoundevent of gridview & use FindControlto apply the same.

或者,您也可以使用RowDataBoundgridview & use 的事件FindControl来应用它。