Click here to Skip to main content
12,696,632 members (31,257 online)
Rate this:
 
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
Updated 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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2017
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