每周的星期一日期显示为GRID视图中的列标题 [英] Each week's monday date show as column header in GRID view
问题描述
我想设计一个网格,其中包含ASP.Net MVC + C中每个资源的每周分配项目的数据#
请帮我设计网格逻辑其中第一列是员工姓名,第一列是第一列,另外52列从当前年份的日历周39开始到下一年的日历第38周,其中每列标题名称是该周的星期一的日期月。 />
例如:
2017-18岁年份
栏目标题:
[员工姓名| 25-Sep | 2-Oct | 9-Oct | 16-Oct | 23-Oct | 30-Oct | .......... | 10-Sep | 9月17日]
---------------------- -------------------------------------------------- --------
[Vaibhav | ABC | ABC | ABC | ABC | ABC | ABC | ........... | XYZ | XYZ]
--------------------------------------------- -----------------------------------
[Pandya | XYZ | XYZ | XYZ | XYZ | XYZ | XYZ | ........... | ABC | ABC]
谢谢,
我尝试了什么:
我是这个网格视图概念和逻辑的新手。
这很简单。想一想!
想象一下,你有一个与DataTable绑定的网格。您需要做的就是定义开始日期和结束日期。然后你必须循环7天。怎么样?请参阅:
CultureInfo myCi = CultureInfo.CurrentCulture;
日历myCal = myCi.Calendar;
CalendarWeekRule myCWR = myCi.DateTimeFormat.CalendarWeekRule;
// 年度第一个星期一
DateTime firstMonday = new DateTime(DateTime.Today.Year, 1 , 1 , MYCAL);
firstMonday = firstMonday.AddDays( - ( int )firstMonday.DayOfWeek +( int )DayOfWeek 。星期一);
// 开始日期
DateTime startDate = myCal.AddWeeks(firstMonday,< span class =code-digit> 38 );
// 结束日期
DateTime endDate = myCal.AddYears(startDate,< span class =code-digit> 1 );
endDate = myCal.AddWeeks(endDate,-1);
DataTable dt = new DataTable();
dt.Columns.Add( new DataColumn( EmpName, typeof ( string )));
// mondays
firstMonday = startDate;
while (firstMonday< endDate)
{
dt.Columns.Add( new DataColumn(firstMonday.ToString( dd MMM yyyy,myCi), typeof ( string )));
firstMonday = firstMonday.AddDays( 7 );
}
// 添加员工姓名
dt.Rows。添加( Maciej Los);
详情请见:
如何:提取一天从特定日期开始的一周| Microsoft Docs [ ^ ]
Calendar.AddWeeks Method(DateTime,Int32)(System.Globalization) [ ^ ]
I want to design a grid which contain data of weekly allocated project to each resource in ASP.Net MVC + C#
Please help me to design a grid logic where first column is Employee Name and against First Column, 52 more columns started from Calendar Week 39 of the current year to Calendar week 38 of the next year where Each column Header name is the Date-Month of the Monday of that week.
For Example:
For year 2017-18
Column Headers:
[Employee Name|25-Sep|2-Oct|9-Oct|16-Oct|23-Oct|30-Oct|..........|10-Sep|17-Sep]
--------------------------------------------------------------------------------
[Vaibhav|ABC|ABC|ABC|ABC|ABC|ABC|...........|XYZ|XYZ]
--------------------------------------------------------------------------------
[Pandya|XYZ|XYZ|XYZ|XYZ|XYZ|XYZ|...........|ABC|ABC]
Thank You,
What I have tried:
I am new with this grid view concept and logic.
It's quite simple. Think of it!
Imagine, you have grid which is binded with DataTable. All what you need to do is to define starting date and ending date. Then you have to loop through 7 days. How? Please see:
CultureInfo myCi = CultureInfo.CurrentCulture; Calendar myCal = myCi.Calendar; CalendarWeekRule myCWR = myCi.DateTimeFormat.CalendarWeekRule; //first Monday of year DateTime firstMonday = new DateTime(DateTime.Today.Year, 1, 1, myCal); firstMonday = firstMonday.AddDays(-(int)firstMonday.DayOfWeek + (int)DayOfWeek.Monday); //start date DateTime startDate = myCal.AddWeeks(firstMonday, 38); //end date DateTime endDate = myCal.AddYears(startDate, 1); endDate = myCal.AddWeeks(endDate, -1); DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("EmpName", typeof(string))); //mondays firstMonday = startDate; while(firstMonday<endDate) { dt.Columns.Add(new DataColumn(firstMonday.ToString("dd MMM yyyy", myCi), typeof(string))); firstMonday = firstMonday.AddDays(7); } //add employee name dt.Rows.Add("Maciej Los");
For further details, please see:
How to: Extract the Day of the Week from a Specific Date | Microsoft Docs[^]
Calendar.AddWeeks Method (DateTime, Int32) (System.Globalization)[^]
这篇关于每周的星期一日期显示为GRID视图中的列标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!