如何根据月份选择创建具有天数的Gridview

问题描述:

我有一个名为attendancemast的表,它有empid,Adate和type(P,A)字段。我想在gridview中显示所有员工的出勤率。其中第一列标题将是员工姓名,其他列标题将是一个月的日期,最后一个标题将显示该月任何员工的当前总天数。





I have table called attendancemast which have empid,Adate and type(P,A) field.I want to display attendance of all employees in a gridview.In which the first column header will be the employee name and other column header will be the dates of a month and last header will show the total number of present days of any employee of that month.


EmpName   01/04/2014  02/04/2014  03/04/2014 .......................................Total 
Sandip       P          P           A                                                 2
Sumit        A          A           P                                                 1





可以你帮助我



Can you help me

我会按如下方式解决问题:



1.使用DateTime。 DaysInMonth获取所选月份的天数。有关详细信息,请参阅: http://msdn.microsoft.com/en -us / library / system.datetime.daysinmonth.aspx [ ^ ]



2.根据天数,动态添加列。有关示例,请参阅:如何动态创建列在网格视图中 [ ^ ]



3.可以通过几种不同的方式来处理总列数;使用公式(具有挑战性,但可行),或者每行只需循环遍历列并计算标记为存在的单元格。
I would break the problem down as follows:

1. Use DateTime.DaysInMonth to get the number of days in the selected month. For more info on this, please see: http://msdn.microsoft.com/en-us/library/system.datetime.daysinmonth.aspx[^]

2. Based on the number of days, dynamically add your columns. For an example, please see: how to create columns dynamically in a grid view[^]

3. The total column may be approached in a couple of different ways; use a formula (challenging, but doable), or for each row simply loop thru the columns and count the cells flagged as present.