C# 如何安排日期时间列表的特殊表格格式
例如,我有这样的C# 如何安排日期时间列表的特殊表格格式,c#,asp.net,repeater,C#,Asp.net,Repeater,例如,我有这样的DateTime列表 List<DateTime> timeList; 但我不能分组日期。如何使用repeater实现此目的?您可以使用此查询进行分组 var query = from t in timeList group t by new { t.Year, t.Month } into g select new { Month = CultureInfo.CurrentCulture.DateTimeFormat
DateTime
列表
List<DateTime> timeList;
但我不能分组日期。如何使用repeater实现此目的?您可以使用此查询进行分组
var query = from t in timeList
group t by new { t.Year, t.Month } into g
select new { Month = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(g.Key.Month),
Year = g.Key.Year,
Dates = g.Select(t => t.Day) };
您可以使用此查询进行分组
var query = from t in timeList
group t by new { t.Year, t.Month } into g
select new { Month = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(g.Key.Month),
Year = g.Key.Year,
Dates = g.Select(t => t.Day) };
首先,创建一个类来保存您的数据:
public class DateInfo
{
public int Year { get; set; }
public string Month { get; set; }
public IEnumerable<int> Days { get; set; }
public string DisplayDayList
{
get
{
return string.Join(" ", Days.Select(x=>x.ToString()).ToArray()); //sorry, i'm doing .net 3.5
}
}
}
公共类日期信息
{
公共整数年{get;set;}
公共字符串月份{get;set;}
公共IEnumerable天{get;set;}
公共字符串DisplayDayList
{
得到
{
return string.Join(“,Days.Select(x=>x.ToString()).ToArray();//对不起,我在做.net 3.5
}
}
}
然后,您可以按年/月分组以绑定列表
List<DateTime> dtList = new List<DateTime>();
List<DateInfo> dateInfoList =
(from dt in dtList
group dt by new { dt.Year, dt.Month } into g
select new DateInfo()
{
Year = g.Key.Year,
Month = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(g.Key.Month),
Days = g.Select(x => x.Day)
}).ToList();
List dtList=newlist();
列表日期信息列表=
(来自dtList中的dt)
按新的{dt.Year,dt.Month}将dt分组为g
选择新建日期信息()
{
年份=g.Key.Year,
Month=CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(g.Key.Month),
天数=g.Select(x=>x.Day)
}).ToList();
现在,使用新的列表对象进行绑定,只绑定
年
、月
和显示日期列表
列。首先,创建一个类来保存数据:
public class DateInfo
{
public int Year { get; set; }
public string Month { get; set; }
public IEnumerable<int> Days { get; set; }
public string DisplayDayList
{
get
{
return string.Join(" ", Days.Select(x=>x.ToString()).ToArray()); //sorry, i'm doing .net 3.5
}
}
}
公共类日期信息
{
公共整数年{get;set;}
公共字符串月份{get;set;}
公共IEnumerable天{get;set;}
公共字符串DisplayDayList
{
得到
{
return string.Join(“,Days.Select(x=>x.ToString()).ToArray();//对不起,我在做.net 3.5
}
}
}
然后,您可以按年/月分组以绑定列表
List<DateTime> dtList = new List<DateTime>();
List<DateInfo> dateInfoList =
(from dt in dtList
group dt by new { dt.Year, dt.Month } into g
select new DateInfo()
{
Year = g.Key.Year,
Month = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(g.Key.Month),
Days = g.Select(x => x.Day)
}).ToList();
List dtList=newlist();
列表日期信息列表=
(来自dtList中的dt)
按新的{dt.Year,dt.Month}将dt分组为g
选择新建日期信息()
{
年份=g.Key.Year,
Month=CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(g.Key.Month),
天数=g.Select(x=>x.Day)
}).ToList();
现在,使用新的列表对象绑定,只绑定
年
、月
和显示日期列表
列。您使用什么数据类型绑定到中继器?您记录了每年/每月的日期列表。在哪里/如何填充的?您能举例说明分组后输出的样子吗。@roughnex问题中的表是output table。所以我的意思是,我想按月份对日期进行分组。@gunr217我无法将DateTime列表绑定到repeater,因为我不知道如何像上面那样绑定。@mehmetice,好的,我再问一遍。您试图绑定到中继器的数据类型是什么?另外,您如何知道哪一天是哪一年/哪一个月?例如:“08、15、22、29转到2012年9月”?您使用什么数据类型绑定到中继器?您记录了每年/每月的日期列表。在哪里/如何填充的?您能举例说明分组后输出的样子吗。@roughnex问题中的表是output table。所以我的意思是,我想按月份对日期进行分组。@gunr217我无法将DateTime列表绑定到repeater,因为我不知道如何像上面那样绑定。@mehmetice,好的,我再问一遍。您试图绑定到中继器的数据类型是什么?另外,您如何知道哪一天是哪一年/哪一个月?比如:“08、15、22、29去2012年9月”?谢谢你的回答:)谢谢你的回答:)