Total Sum Value of columns as header row by "LabourID" in gridview

Csharp , asp.net , javascript Myanmar
  • 5 years ago

    The GridView columns are as follow:

    The result must be: .................................................................................................................................................. LabourID | Name | Event Name| Working Date | Normal(Hr) | Amt(N) | .... | Total ..................|.............|........................|..........................|.......................|...............|........|............ 009 |ET | All | All | 5 | 35.0 | ... |95.0 --->Sum of each column by laborID ..................|.............|........................|..........................|.......................|...............|........|............ | | Meeting | 10 Jul 09 | 2 | 20.0 | ... |60.0 ..................|.............|........................|..........................|.......................|...............|........|............ | | Seminar | 13 Jul 09 | 3 | 15.0 | ... | 35.0 ..................|.............|........................|..........................|.......................|...............|........|............ 002 |Sue | All | All | 6 | 18.0 | ... |40.0
    ..................|.............|........................|..........................|.......................|...............|........|............ | | Promotion | 23 Jul 09 | 6 | 18.0 | ... |40.0 ..................|.............|........................|..........................|.......................|...............|........|............

    I'm writing the code as follow:

     void GetDataTable(DataTable tempDT)
        {
            DataTable dt_FromDB = tempDT;
            DataTable dt_Grid = Grid_Table;
     //       DataRow adr = new DataRow();
    
            decimal nHour=0;
            decimal nRate=0;
            decimal eHour=0;
            decimal eRate=0;
            decimal hHour=0;
            decimal hRate=0;
            decimal wHour=0;
            decimal wRate=0;
            decimal allow=0;
            decimal total=0;
    
            string labourNRIC = "";
            string checkLabourNRIC = "";
    
    
            foreach (DataRow dr_FromDB in dt_FromDB.Rows)
            {
                //string NRIC=dr_FromDB["NRIC"].ToString();
                //while(dt_FromDB.Select("NRIC="+NRIC))
                //{
                if(dr_FromDB["NRIC"].ToString()==labourNRIC || labourNRIC=="")
                {
                    nHour += Convert.ToDecimal(dr_FromDB["NormalHour"].ToString());
                    nRate += Convert.ToDecimal(dr_FromDB["NormalRate"].ToString());
                    eHour += Convert.ToDecimal(dr_FromDB["ExtraHour"].ToString());
                    eRate += Convert.ToDecimal(dr_FromDB["ExtraRate"].ToString());
                    hHour += Convert.ToDecimal(dr_FromDB["HolidayHour"].ToString());
                    hRate += Convert.ToDecimal(dr_FromDB["HolidayRate"].ToString());
                    wHour += Convert.ToDecimal(dr_FromDB["WeekEndHour"].ToString());
                    wRate += Convert.ToDecimal(dr_FromDB["WeekEndRate"].ToString());
                    allow += Convert.ToDecimal(dr_FromDB["Allowance"].ToString());
                    total += Convert.ToDecimal(dr_FromDB["Total"].ToString());
                }
    
                if (dr_FromDB["NRIC"].ToString() != checkLabourNRIC)
                {
                    labourNRIC = dr_FromDB["NRIC"].ToString();
    
                    DataRow dr_Grid = dt_Grid.NewRow();
                    dr_Grid["NRIC"] = dr_FromDB["NRIC"].ToString();
                    dr_Grid["LabourName"] = dr_FromDB["LabourName"].ToString();
                    dr_Grid["EventNameOrDutyRoster"] = "All";
                    dr_Grid["WorkingDate"] = "All";
                    dr_Grid["NormalHour"] = nHour;
                    dr_Grid["NormalRate"] = nRate;
                    dr_Grid["ExtraHour"] = eHour;
                    dr_Grid["ExtraRate"] = eRate;
                    dr_Grid["HolidayHour"] = hHour;
                    dr_Grid["HolidayRate"] = hRate;
                    dr_Grid["WeekEndHour"] = wHour;
                    dr_Grid["WeekEndRate"] = wRate;
                    dr_Grid["Allowance"] = allow;
                    dr_Grid["Total"] = total;
                    dt_Grid.Rows.Add(dr_Grid);
                    ViewState["Grid"] = dt_Grid;
                }
    
                if (dr_FromDB["NRIC"].ToString() == labourNRIC)
                {
                    DataRow dr_Grid = dt_Grid.NewRow();
                    dr_Grid["EventNameOrDutyRoster"] = dr_FromDB["EventNameOrDutyRoster"].ToString();
                    dr_Grid["WorkingDate"] = dr_FromDB["WorkingDate"].ToString();
                    dr_Grid["NormalHour"] = dr_FromDB["NormalHour"].ToString();
                    dr_Grid["NormalRate"] = dr_FromDB["NormalRate"].ToString();
                    dr_Grid["ExtraHour"] = dr_FromDB["ExtraHour"].ToString();
                    dr_Grid["ExtraRate"] = dr_FromDB["ExtraRate"].ToString();
                    dr_Grid["HolidayHour"] = dr_FromDB["HolidayHour"].ToString();
                    dr_Grid["HolidayRate"] = dr_FromDB["HolidayRate"].ToString();
                    dr_Grid["WeekEndHour"] = dr_FromDB["WeekEndHour"].ToString();
                    dr_Grid["WeekEndRate"] = dr_FromDB["WeekEndRate"].ToString();
                    dr_Grid["Allowance"] = dr_FromDB["Allowance"].ToString();
                    dr_Grid["Total"] = dr_FromDB["Total"].ToString();
                    dr_Grid["Type"] = dr_FromDB["Type"].ToString();
                    dt_Grid.Rows.Add(dr_Grid);
                    ViewState["Grid"] = dt_Grid;
    
                    checkLabourNRIC = labourNRIC;
                }
    
            }
    

    How shall I continue this code? Thanks for your help.

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“If Java had true garbage collection, most programs would delete themselves upon execution.” - Robert Sewell