locked
How To Convert Null Values To Zero Default RRS feed

  • Question

  • User2033107836 posted

    Hello

    This is my code

      Label yzlblPgTotal = (Label)e.Row.FindControl("Label7");
                dPageTotalArrivalsecond += Decimal.Parse(yzlblPgTotal.Text);
    
    
     Label yzlblPageTotal = (Label)e.Row.FindControl("LF3");
                yzlblPageTotal.Text = dPageTotalArrivalsecond.ToString("#.##");

    If my value is null then im getting error

    Modify my code and give me the right code which accept null as well and make total

    Tuesday, March 28, 2017 9:39 AM

Answers

  • User-1509636757 posted

    Check for Null and initialize decimal dPageTotalArrivalsecond to 0 value before using it.

    Label yzlblPgTotal = e.Row.FindControl("Label7") as Label;
    if (null != yzlblPgTotal)
    {
        decimal tempVal = 0M;
        Decimal.TryParse(yzlblPgTotal.Text, out tempVal);
        dPageTotalArrivalsecond += tempVal;
    }
    
    Label yzlblPageTotal = e.Row.FindControl("LF3") as Label;
    if (null != yzlblPageTotal)
    {
        yzlblPageTotal.Text = dPageTotalArrivalsecond.ToString("#.##");
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 28, 2017 9:57 AM