I have two pages main page have grid view it works fine the second page is redirect result from main page that is also work fine, but when calculate sum of selected row it does not show to the redirec

Here is the code from main page:
 private void SendGridInfo()

            DataTable dt = new DataTable();
            DataRow dr = default(DataRow);
            dt.Columns.Add(new System.Data.DataColumn("Invoice Number", typeof(string)));
            dt.Columns.Add(new System.Data.DataColumn("Original Amount", typeof(string)));
            dt.Columns.Add(new System.Data.DataColumn("Remaining Amount", typeof(string)));
            dt.Columns.Add(new System.Data.DataColumn("Amount To Pay", typeof(string)));

            foreach (GridViewRow row in GridView2.Rows)
                if (row.RowType == DataControlRowType.DataRow)
                    CheckBox chk = (CheckBox)row.FindControl("chkSelect");
                    Label label0 = (Label)row.FindControl("Label0") as Label;
                    Label label3 = row.FindControl("Label3") as Label;
                    Label label4 = (Label)row.FindControl("Label4") as Label;
                    TextBox textbox1 = (TextBox)row.FindControl("txtRemainingAmount") as TextBox;

                    if (chk.Checked)
                        dr = dt.NewRow();
                        dr[0] = label0.Text;
                        dr[1] = label3.Text;
                        dr[2] = label4.Text;
                        dr[3] = textbox1.Text;
            Session["GridData"] = dt;
            RedirectTo("Selected Invoice");
the redirected page code is:
 protected void Page_Load(object sender, EventArgs e)

            if (Session["GridData"] != null)
                DataTable dt = (DataTable)Session["GridData"];
                GridView2.DataSource = dt;
Who is Participating?
array12Connect With a Mentor Author Commented:
I did this,
for(int I =0; I<GridView2.Rows.Count-1; I++)
    CheckBox chkb = GridView2.Rows[i].FindControl("chkSelect") as CheckBox;
          if (chkb.Checked == true)
but no luck

Open in new window

Kamal KhaleefaConnect With a Mentor Information Security SpecialistCommented:
you need to make a for loop on you datatable and loop for each row and add sum all the values
then you can show it on the page
array12Author Commented:
I've requested that this question be deleted for the following reason:

I solved this problem by my self.
Kamal KhaleefaInformation Security SpecialistCommented:
my suggestion help you to create your code

i deserve the points
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.