gpt4 book ai didi

c# - 列出一个月中的所有日期 ASP.NET C#

转载 作者:行者123 更新时间:2023-12-02 15:24:11 26 4
gpt4 key购买 nike

我想生成一个包含一个月中所有日期的数据透视表,如下图所示。

enter image description here

有没有办法在 sql 或 c# 中动态生成日期列表?月份和年份绑定(bind)到下拉菜单,手动填写。

   <asp:Label ID="LlbMes" runat="server" Text="Mês"></asp:Label>
</td>
<td> <%--Months--%>
<asp:DropDownList ID="DDMes" runat="server" Height="18px" Width="90px">
<asp:ListItem Text="Janeiro" Value="1"></asp:ListItem>
<asp:ListItem Text="Fevereiro" Value="2"></asp:ListItem>
<asp:ListItem Text="Março" Value="3"></asp:ListItem>
<asp:ListItem Text="Abril" Value="4"></asp:ListItem>
<asp:ListItem Text="Maio" Value="5"></asp:ListItem>
<asp:ListItem Text="Junho" Value="6"></asp:ListItem>
<asp:ListItem Text="Julho" Value="7"></asp:ListItem>
<asp:ListItem Text="Agosto" Value="8"></asp:ListItem>
<asp:ListItem Text="Setembro" Value="9"></asp:ListItem>
<asp:ListItem Text="Outubro" Value="10"></asp:ListItem>
<asp:ListItem Text="Novembro" Value="11"></asp:ListItem>
<asp:ListItem Text="Dezembro" Value="12"></asp:ListItem>
</asp:DropDownList>&nbsp;&nbsp;
</td>
<td>
<asp:Label ID="LlbAno" runat="server" Text="Ano"></asp:Label>
</td>
<td><%-- Years--%>
<asp:DropDownList ID="DDAno" runat="server" Height="18px" Width="90px">
<asp:ListItem Value="2015">2015</asp:ListItem>
<asp:ListItem Value="2014">2014</asp:ListItem>
<asp:ListItem Value="2013">2013</asp:ListItem>
<asp:ListItem Value="2012">2012</asp:ListItem>
<asp:ListItem Value="2011">2011</asp:ListItem>
<asp:ListItem Value="2010">2010</asp:ListItem>
<asp:ListItem Value="2009">2009</asp:ListItem>
<asp:ListItem Value="2008">2008</asp:ListItem>
<asp:ListItem Value="2007">2007</asp:ListItem>
<asp:ListItem Value="2006">2006</asp:ListItem>
<asp:ListItem Value="2005">2005</asp:ListItem>
<asp:ListItem Value="2004">2004</asp:ListItem>
<asp:ListItem Value="2003">2003</asp:ListItem>
<asp:ListItem Value="2002">2002</asp:ListItem>
<asp:ListItem Value="2001">2001</asp:ListItem>
</asp:DropDownList>

最佳答案

 List<DateTime> daysOfMonth = Enumerable.Range(1, DateTime.DaysInMonth(year, month))  // Days: 1, 2 ... 31 etc.
.Select(day => new DateTime(year, month, day)) // Map each day to a date
.ToList();

以上返回特定年份中特定月份的天数

关于c# - 列出一个月中的所有日期 ASP.NET C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31720485/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com