protected void grdAttendanceHistory_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //0         1           2           3               4
        //ID        Term        Date        Pro-rate        Present
        //5         6
        //Absent    Make-up
        if (e.Row.RowType == DataControlRowType.Header)
        {
            proRateT = 0;
            presentT = 0;
            absentT = 0;
            makeupT = 0;
            transitionRow = null;
            partitionSize = 1;
            prevIdTC = -1;
        }
        else if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //ID
            int attId = Convert.ToInt32(e.Row.Cells[0].Text);
            string temp;

            //load Att Object
            BCAttendance objBCAtt = new BCAttendance();
            objBCAtt.Id = attId;
            try
            {
                objBCAtt.LoadData();
            }
            catch (WebServiceException ex)
            {
                bool rethrow = ExceptionPolicy.HandleException(ex, "GenericPolicy");
                if (rethrow) throw;
                return;
            }

            //Date
            e.Row.Cells[2].Text = objBCAtt.DateAttendance.ToString("dd MMM yyyy");

            //Term
            wsvTermCalendar.TermCalendar dbTC = new wsvTermCalendar.TermCalendar();
            wsvTermCalendar.CTerm objT =
                dbTC.GetTermOf(objBCAtt.DateAttendance);
            if (objT == null)
            {
                e.Row.Cells[1].Text = "Nil";
            }
            else
            {
                BCTerm objBCT = new BCTerm();
                objBCT.TransferFromWsv(objT);
                e.Row.Cells[1].Text = objBCT.ToString();
            }

            //do rowspan of Term column
            int curIdTC = (objT == null) ? -1 : objT.Id;
            if (transitionRow == null)
            {
                //first row
                transitionRow = e.Row;
                partitionSize = 1;
                prevIdTC = curIdTC;
            }
            else
            {
                if (prevIdTC == curIdTC)
                {
                    partitionSize++;
                    e.Row.Cells[1].Visible = false;
                    transitionRow.Cells[1].RowSpan = partitionSize;

                }
                else
                {
                    //"close" previous transition row
                    transitionRow.Cells[1].RowSpan = partitionSize;

                    transitionRow = e.Row;
                    partitionSize = 1;
                    prevIdTC = curIdTC;
                }
            }

            //Pro-rate, present, absent
            int isPresent = Convert.ToInt32(e.Row.Cells[3].Text);
            //0 = absent, 1 = present, 2 = pro-rate
            string imgString = "<img src='images/tick.jpg'>";
            string noImgString = " ";
            switch (isPresent )
            {
                case 0:
                    absentT++;
                    e.Row.Cells[3].Text = noImgString;
                    e.Row.Cells[4].Text = noImgString;
                    e.Row.Cells[5].Text = imgString;
                    break;
                case 1:
                    presentT++;
                    e.Row.Cells[3].Text = noImgString ;
                    e.Row.Cells[4].Text = imgString;
                    e.Row.Cells[5].Text = noImgString;
                    break;
                case 2:
                    proRateT++;
                    e.Row.Cells[3].Text = imgString;
                    e.Row.Cells[4].Text = noImgString;
                    e.Row.Cells[5].Text = noImgString;
                    break;
            }

            //makeup
            BCAttendanceLn objBCAttln = new BCAttendanceLn();
            objBCAttln.IdAttendance = attId;
            objBCAttln.IdUser = Convert.ToInt32(hdnStudentId.Value);
            if (objBCAttln.HasMakeupAttendance())
            {
                makeupT++;
                BCMakeupAttendance objMkAtt = objBCAttln.GetMakeupAttendance();
                //load one time class attendance and class details.
                BCAttendance objOTAtt = new BCAttendance();
                BCOneTime objOT = new BCOneTime();
                BCSlot[] arySlots;
                objOTAtt.Id = objMkAtt.IdAttendanceOneTime;
                try
                {
                    objOTAtt.LoadData();
                    objOT.Id = objOTAtt.IdClass;
                    objOT.LoadData();
                    arySlots = objOT.getSlots();
                    string timeSlotInfo = "&nbsp;";

                    //find slot with matching date
                    if (arySlots == null || arySlots.Length ==0)
                    {
                        timeSlotInfo = "&nbsp;";
                    }
                    else
                    {
                        foreach (BCSlot objSlot in arySlots)
                        {
                            if (objSlot.DateSlot.Equals(objOTAtt.DateAttendance))
                            {
                                DateTime dtmTimeStart = DateTime.Parse(objSlot.TimeStart);
                                DateTime dtmTimeEnd = DateTime.Parse(objSlot.TimeEnd);
                                timeSlotInfo =
                                    dtmTimeStart.ToString("hh:mm tt") +
                                    " - " +
                                    dtmTimeEnd.ToString("hh:mm tt");
                            }
                        }
                    }

                    temp = "{0} {1}<br>{2}<br>{3}";
                    e.Row.Cells[6].Text = String.Format(temp,
                        objOT.getLevel().Name,
                        objOT.GetSubject().name,
                        objOTAtt.DateAttendance.ToString("dd MMM yyyy"),
                        timeSlotInfo);

                }
                catch (WebServiceException ex)
                {

                    bool rethrow = ExceptionPolicy.HandleException(ex, "GenericPolicy");
                    if (rethrow) throw;
                }

            }

        }
        else if (e.Row.RowType == DataControlRowType.Footer)
        {
            //0         1           2           3               4
            //ID        Term        Date        Pro-rate        Present
            //5         6
            //Absent    Make-up
            e.Row.Cells[2].Text = "Total:";
            e.Row.Cells[2].HorizontalAlign = HorizontalAlign.Right;

            e.Row.Cells[3].Text = Convert.ToString(proRateT);
            e.Row.Cells[4].Text = Convert.ToString(presentT);
            e.Row.Cells[5].Text = Convert.ToString(absentT);
            e.Row.Cells[6].Text = "Total Makeup: " + Convert.ToString(makeupT);
        }
    }
    protected void grdPaymentHistory_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //0         1           2           3               4
        //ID        Term        Date        Recepit No.     Payment Mode
        //5             6           7
        //Amount        Credit      Remark
        if (e.Row.RowType == DataControlRowType.Header)
        {
            amtT = 0;
            creditT = 0;
            transitionRow = null;
            prevIdTC = -1;
            partitionSize = 0;
        }
        else if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //PaymentId
            int pId = Convert.ToInt32(
                e.Row.Cells[0].Text
                );

            //Date, Term
            DateTime tempDate = Convert.ToDateTime(e.Row.Cells[2].Text);
            wsvTermCalendar.TermCalendar dbTC = new wsvTermCalendar.TermCalendar();
            wsvTermCalendar.CTerm objT =
                dbTC.GetTermOf(tempDate);

            e.Row.Cells[2].Text = tempDate.ToString("dd MMM yyyy"); //date
            //term
            if (objT == null)
            {
                e.Row.Cells[1].Text = "Nil";
            }
            else
            {
                BCTerm objBCT = new BCTerm();
                objBCT.TransferFromWsv(objT);
                e.Row.Cells[1].Text = objBCT.ToString();
            }

            //do rowspan of Term column
            int curIdTC = (objT == null) ? -1 : objT.Id;
            if (transitionRow == null)
            {
                //first row
                transitionRow = e.Row;
                partitionSize = 1;
                prevIdTC = curIdTC;
            }
            else
            {
                if (prevIdTC == curIdTC)
                {
                    partitionSize++;
                    e.Row.Cells[1].Visible = false;
                    transitionRow.Cells[1].RowSpan = partitionSize;

                }
                else
                {
                    //"close" previous transition row
                    transitionRow.Cells[0].RowSpan = partitionSize;

                    transitionRow = e.Row;
                    partitionSize = 1;
                    prevIdTC = curIdTC;
                }
            }

            //Recepit No
            BCPayment objBCPayment = new BCPayment();
            objBCPayment.Id = pId;
            e.Row.Cells[3].Text = objBCPayment.GetReceiptNumber();

            //Amount
            amtT += Convert.ToDouble(e.Row.Cells[5].Text);
            e.Row.Cells[5].Text = "$" + e.Row.Cells[5].Text;

            //credit
            creditT += Convert.ToInt32(e.Row.Cells[6].Text);

            //Remark. Display fee deviations
            string temp = "";
            BCFeeDeviation oFD = new BCFeeDeviation();
            BCFeeDeviation[] aryFD = oFD.getFeeDeviationByPayment(pId);
            if (aryFD != null)
            {
                temp = "Includes:";
                foreach (BCFeeDeviation objFD in aryFD)
                {
                    objFD.LoadData();
                    temp += "<br>"+ objFD.Description + "<br>";
                    if (objFD.isAddition)
                    {
                        temp += "(+$" + objFD.Amount +")";
                    }
                    else
                    {
                        temp += "(-$" + objFD.Amount+")";
                    }
                }
            }

            e.Row.Cells[7].Text = temp;

        }
        else if (e.Row.RowType == DataControlRowType.Footer)
        {
            e.Row.Cells[5].Text = "$" + amtT;
            e.Row.Cells[6].Text = Convert.ToString(creditT);
        }
    }