Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
i am Perform Calculation in grid view but he give error
An exception of type 'System.NullReferenceException' occurred in App_Web_pbkfehdc.dll but was not handled in user code
Additional information: Object reference not set to an instance of an object.
 
protected void Grd_RowDataBound(object seder, GridViewRowEventArgs e)
    {            
        foreach (GridViewRow Row in Grd.Rows)
        {
            TextBox TxtNum1 = (TextBox)e.Row.FindControl("Text2");
            TextBox TxtNum2 = (TextBox)e.Row.FindControl("Text1");
            TextBox TxtNum3 = (TextBox)e.Row.FindControl("Text3");
            float Num1, num2, num3;
            Num1 = Convert.ToSingle(TxtNum1.Text);
            num2 = Convert.ToSingle(TxtNum2.Text);
            num3 = Num1 + num2;
            TxtNum3.Text = Convert.ToString(num3);
        }
    }
 
Updated: [Code block]
Posted 17-Dec-12 22:35pm
Edited 17-Dec-12 22:41pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

protected void Grd_RowDataBound(object seder, GridViewRowEventArgs e)
    {            
        foreach (GridViewRow Row in Grd.Rows)
        {
            TextBox TxtNum1 = (TextBox)e.Row.FindControl("Text2");
            TextBox TxtNum2 = (TextBox)e.Row.FindControl("Text1");
            TextBox TxtNum3 = (TextBox)e.Row.FindControl("Text3");
            float Num1, num2, num3;
            
            if(TxtNum1.Text!="")
            {
            Num1 = Convert.ToSingle(TxtNum1.Text);
            }
            if(TxtNum2.Text!="")
            {
            num2 = Convert.ToSingle(TxtNum2.Text);
            }
            num3 = Num1 + num2;
            if(num3!=null)
            {
            TxtNum3.Text = Convert.ToString(num3);
            }
        }
    }
  Permalink  
Comments
manoj s sherje at 19-Dec-12 3:14am
   
Sir his not Working He Give Same Error
An exception of type 'System.NullReferenceException' occurred in App_Web_czhkbo_j.dll but was not handled in user code
 
Additional information: Object reference not set to an instance of an object.
 
please help me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 495
1 Maciej Los 258
2 OriginalGriff 229
3 BillWoodruff 170
4 Zoltán Zörgő 165
0 OriginalGriff 7,934
1 DamithSL 6,084
2 Sergey Alexandrovich Kryukov 5,449
3 Maciej Los 5,174
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100