将DefaultValue设置为当前月份的第一个和最后一个日期

Sar*_*nya 5 c# asp.net

如何DefaultValue将以下代码中的's 设置为当前月份的开始日期(第一个ControlParameter)和最后一个日期(第二个ControlParameter)

<SelectParameters>
    <asp:ControlParameter ControlID="txtFromDate" Name="ExpenseDate" PropertyName="Text"
         Type="String" DefaultValue="01-05-2013" ConvertEmptyStringToNull="true" />
    <asp:ControlParameter ControlID="txtToDate" Name="ExpenseDate2" PropertyName="Text" 
         Type="String" DefaultValue="30-05-2013" ConvertEmptyStringToNull="true" />
</SelectParameters>
Run Code Online (Sandbox Code Playgroud)

Sem*_*glu 16

DateTime today = DateTime.Today;
int daysInMonth = DateTime.DaysInMonth(today.Year, today.Month);

DateTime startOfMonth = new DateTime(today.Year, today.Month, 1);    
DateTime endOfMonth = new DateTime(today.Year, today.Month, daysInMonth);
Run Code Online (Sandbox Code Playgroud)

然后,您可以将这些值设置为控件.