Pergunta

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.

<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>
Foi útil?

Solução

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 RowDataBound event of gridview & use FindControl to apply the same.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top