Weekstartdate MOn Tue Wed thr fri sat Sun total 03/18/2013 8 8 8 8 8 0 0 40 03/25/2013 8 8 8 8 8 0 0 40
foreach (ManageTimeSheetsModel objTimesheet in objManageTimeSheetsModelLst) { weekDay = (int)objTimesheet.Timesheetdate.DayOfWeek; switch (weekDay.ToString()) { case "1": objTimesheetweekdaysModel.Mon = objTimesheet.Workinghours.ToString(); break; case "2": objTimesheetweekdaysModel.Tue = objTimesheet.Workinghours.ToString(); break; case "3": objTimesheetweekdaysModel.Wed = objTimesheet.Workinghours.ToString(); break; case "4": objTimesheetweekdaysModel.Thu = objTimesheet.Workinghours.ToString(); break; case "5": objTimesheetweekdaysModel.Fri = objTimesheet.Workinghours.ToString(); break; case "6": objTimesheetweekdaysModel.Sat = objTimesheet.Workinghours.ToString(); break; case "0": objTimesheetweekdaysModel.Sun = objTimesheet.Workinghours.ToString(); objTimesheetweekdaysMdlList.Add(objTimesheetweekdaysModel); objTimesheetweekdaysModel = new TimesheetweekdaysModel(); objTimesheetweekdaysModel.WeekDate = objTimesheet.Timesheetdate.AddDays(1).ToShortDateString(); break; } } if (objTimesheetweekdaysModel.Sun != null || objTimesheetweekdaysModel.Mon != null || objTimesheetweekdaysModel.Tue != null || objTimesheetweekdaysModel.Wed != null || objTimesheetweekdaysModel.Thu != null || objTimesheetweekdaysModel.Fri != null || objTimesheetweekdaysModel.Sat != null) { objTimesheetweekdaysMdlList.Add(objTimesheetweekdaysModel); } return objTimesheetweekdaysMdlList; }
<pre lang="cs">protected void GridViewWeeklyTimesheet_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { decimal total = Convert.ToDecimal(e.Row.Cells[1].Text) + Convert.ToDecimal(e.Row.Cells[2].Text) + Convert.ToDecimal(e.Row.Cells[3].Text) + Convert.ToDecimal(e.Row.Cells[4].Text) + Convert.ToDecimal(e.Row.Cells[5].Text) + Convert.ToDecimal(e.Row.Cells[6].Text) + Convert.ToDecimal(e.Row.Cells[7].Text); ((Label)GridViewWeeklyTimesheet.FindControl("TotalHours")).Text = Convert.ToString(total); }
SELECT Mon, Tue, Wed, Thr, Fri, Sat, Sun, (Mon+Tue+Wed+Thr+Fri+Sat+Sun) AS 'Total' FROM YourTableName
protected void GridViewWeeklyTimesheet_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.Cells[1].Text != "") { decimal total = Convert.ToDecimal(e.Row.Cells[1].Text) + Convert.ToDecimal(e.Row.Cells[2].Text) + Convert.ToDecimal(e.Row.Cells[3].Text) + Convert.ToDecimal(e.Row.Cells[4].Text) + Convert.ToDecimal(e.Row.Cells[5].Text) + Convert.ToDecimal(e.Row.Cells[6].Text) + Convert.ToDecimal(e.Row.Cells[7].Text); ((Label)GridViewWeeklyTimesheet.FindControl("TotalHours")).Text = Convert.ToString(total); } } }
<asp:TemplateField HeaderText="TotalHours"> <ItemTemplate> <asp:Label runat="server" ID="lblWeekTotalHrs" Text='<%# Convert.ToDecimal(Eval("Mon")) + Convert.ToDecimal(Eval("Tue")) + Convert.ToDecimal(Eval("Wed")) + Convert.ToDecimal(Eval("Thu")) + Convert.ToDecimal(Eval("Fri")) + Convert.ToDecimal(Eval("Sat")) + Convert.ToDecimal(Eval("Sun"))%>' /> </ItemTemplate> </asp:TemplateField>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)