Replace NaN To Empty For Eval Label

RAVI 916 Reputation points
2024-03-12T10:16:15.68+00:00

Hello

This is my code

                    
                    <asp:TemplateField HeaderText="FEB">
                        <FooterTemplate>
                            <asp:Label ID="FB2" runat="server" Font-Size="16px" ForeColor="red"></asp:Label><br />
                            <asp:Label ID="FB22" runat="server" Font-Size="16px" ForeColor="teal"></asp:Label>
                        </FooterTemplate>
                        <ItemTemplate>
                            <asp:Label ID="B2" runat="server" ForeColor="Red" Text='<%#(String.IsNullOrEmpty(Eval("[February QTY]").ToString()) ? "" : Eval("[February QTY]"))%>'
                                 ></asp:Label><br />
                            <asp:Label ID="B22" runat="server" Font-Size="20px" ForeColor="Black" Text='<%# String.IsNullOrEmpty(Eval("[February VALUE]").ToString()) ? "" : (String.Format(System.Globalization.CultureInfo.CreateSpecificCulture("hi-IN"), "{0:#,#}" , decimal.Parse(Eval("[February VALUE]").ToString())))%>'>
           </asp:Label>
           
             <br /> 
         <asp:Label ID="B222" ForeColor="Blue" Font-Size="22px" runat="server" Text='<%# ((Eval("February VALUE")!= DBNull.Value ? Convert.ToDouble(Eval("February VALUE")) : 0) / (Eval("[February QTY]")!= DBNull.Value ? Convert.ToDouble(Eval("[February QTY]")) : 0)).ToString("N2") %>'></asp:Label>
        
                        </ItemTemplate>
                        <FooterStyle Font-Size="26px" ForeColor="Teal" HorizontalAlign="Right" />
                        <HeaderStyle ForeColor="Black" BackColor="#FCF3CF" Font-Size="20px" />
                        <ItemStyle ForeColor="Teal" HorizontalAlign="Right" Width="100px" />
                        <ControlStyle Width="100px" />
                    </asp:TemplateField>

It shows on load Label B222 NaN how to make this NaN to empty

Thanking You

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,288 questions
0 comments No comments
{count} votes

Accepted answer
  1. Lan Huang-MSFT 25,876 Reputation points Microsoft Vendor
    2024-03-13T02:26:25.4133333+00:00

    Hi @RAVI,

    When 0/0, value = NaN. So you can use the Double.IsNaN(Double) method to judge.

     <asp:Label ID="B222" ForeColor="Blue" Font-Size="22px" runat="server" Text='<%# Double.IsNaN((Eval("[February VALUE]")!= DBNull.Value ? Convert.ToDouble(Eval("[February VALUE]")) : 0) / (Eval("[February QTY]")!= DBNull.Value ? Convert.ToDouble(Eval("[February QTY]")) : 0)) ? " " : ((Eval("February VALUE")!= DBNull.Value ? Convert.ToDouble(Eval("February VALUE")) : 0) / (Eval("[February QTY]")!= DBNull.Value ? Convert.ToDouble(Eval("[February QTY]")) : 0)).ToString("N2") %>'></asp:Label>
    

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful