Thursday, 7 July 2016

Auto Calculate (Sum) Bound Field Dynamic Gridview columns values and result shows Text Box or Label :

 Step 1: Add Text Box changed event in code behind page.       

 ontextchanged="TextBox1_TextChanged"
   

Step 2: Add code in your C#  page.

   protected void TextBox1_TextChanged(object sender, EventArgs e)

    {

        double total = 0;

             foreach (GridViewRow gvr in Gridview1.Rows)

        {

            TextBox tb = (TextBox)gvr.Cells[5].FindControl("Column1");

//Add column name insted of Column1 and Enter column cell index correctly.

            double sum;

            if (double.TryParse(tb.Text.Trim(), out sum))

            {

                total += sum;

            }

                   }

        totltxt.Text = total.ToString();

//You want to display label or textbox .

    }    


Step 3: Screen Shot.




    

No comments:

Post a Comment

How to create a simple Hello World website in ASP.NET MVC using Razor Syntax: (Note: I am using Visual Studio 2012 ) Step 1: ...