Click here to Skip to main content
15,308,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am currently getting data from database, then if i checked the checkbox more than 2 rows, it will sum up the total of SENDQTY and send the details from GridView3 to GridView4.

What I have tried:

Now how can i check if the STOCKCODE from the 2 rows is different, it will prompt error message?

C#
protected void showGridView()
        {
            int match = 0;
            int total = 0;
          
            DataTable dt = new DataTable();
            dt.Columns.AddRange(new DataColumn[9] { new DataColumn("DODetailID"), new DataColumn("SALESORDERNO"), new DataColumn("STOCKCODE"), new DataColumn("SENDQTY"), new DataColumn("scanflag"), new DataColumn("REJECT"), new DataColumn("DispatchOrderID"), new DataColumn("DispatchDATE"), new DataColumn("DELORDERNO") });
            foreach (GridViewRow row in GridView3.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    CheckBox CheckBox1 = (row.Cells[0].FindControl("CheckBox1") as CheckBox);

                    //int qty = Convert.ToInt32(row.Cells[4].Text);

                    if (CheckBox1.Checked)
                    {
                        string DODetailID = (row.Cells[1].FindControl("DODetailID") as Label).Text;
                        string SALESORDERNO = (row.Cells[2].FindControl("SALESORDERNO") as Label).Text;
                        string STOCKCODE = (row.Cells[3].FindControl("STOCKCODE") as Label).Text;                 
                        int SENDQTY = Convert.ToInt32((row.Cells[4].FindControl("SENDQTY") as Label).Text);
                        CheckBox scanflag = (row.Cells[5].FindControl("scanflag") as CheckBox);
                        string REJECT = (row.Cells[6].FindControl("REJECT") as Label).Text;
                        string DispatchOrderID = (row.Cells[7].FindControl("DispatchOrderID") as Label).Text;
                        string DispatchDATE = (row.Cells[8].FindControl("DispatchDATE") as Label).Text;
                        string DELORDERNO = (row.Cells[9].FindControl("DELORDERNO") as Label).Text;
                        Session["STOCKCODE"] = STOCKCODE.ToString();
                       
                            dt.Rows.Add(DODetailID, SALESORDERNO, STOCKCODE, SENDQTY, scanflag, REJECT, DispatchOrderID, DispatchDATE, DELORDERNO);
                            match++;
                       
                            total = total + SENDQTY;
                            GridView4.DataSource = dt;
                            GridView4.DataBind();
                        
                       
                    }
                   
                }
            }
       

        }

   protected void btnContinue_Click(object sender, EventArgs e)
        {  
               showGridView();

                mp3.Show(); // this is showing GridView4
        }
Posted
Updated 15-Mar-21 23:19pm
v2

1 solution

Why to force doors wide open?

Please, read this: Displaying Summary Information in the GridView's Footer (C#) | Microsoft Docs[^]

In case you still want to get sum of SENDQTY data for selected rows only, you need to loop through the collection of selected rows. See: GridView.SelectedRow Property (System.Web.UI.WebControls) | Microsoft Docs[^]
   

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