Click here to Skip to main content
11,578,006 members (63,262 online)
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 21:35pm
Edited 17-Dec-12 21: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 Richard MacCutchan 165
1 Peter Leow 150
2 OriginalGriff 120
3 Afzaal Ahmad Zeeshan 100
4 Frankie-C 85
0 OriginalGriff 880
1 Sergey Alexandrovich Kryukov 685
2 Abhinav S 573
3 F-ES Sitecore 420
4 Suvendu Shekhar Giri 393


Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2015
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