Click here to Skip to main content
16,020,249 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI.


I was taken one grid view, in that gridview there is 6 text boxes are there (sun1b,mon1b,...... total1b), I want to add (sum) those textbox valus without ''ADD Button ''click .

It is possible to add the textbox values ? pls help me!!
Posted

I do not actually get the exact problem. But here is how to get the textbox values inside a gridview and sum it.

C#
TextBox txt1;
TextBox txt2;
int sumPerRow = 0;
foreach(GridViewRow row in GridView1.Rows)
{
   txt1 = (TextBox)row.Cells[0].FindControl("sun1b");
   if(String.IsNullOrEmpty(txt1.Text))
   {
      txt1.Text = "0";
   }
   txt2 = (TextBox)row.Cells[1].FindControl("mon1b");
   if(String.IsNullOrEmpty(txt2.Text))
   {
      txt2.Text = "0";
   }

   sumPerRow = Convert.ToInt32(txt1.Text) + Convert.ToInt32(txt2.Text);
}


Hope you get it from here. The logic is there my friend. :)

Regards,
Eduard
 
Share this answer
 
v3
This is possible. from above solution you will get how to add the textbox values. But be sure that value enter that must be numeric not alphanumeric or any other symbol, for this use validation also.
From this you will do easy calculation without any error.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900