Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting DefaultValue to first and last date of current month

Tags:

c#

asp.net

How can I set the DefaultValue's in the following code to the start date (first ControlParameter) and last date (second ControlParameter) of the current month?

<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>
like image 219
Saranya Avatar asked May 14 '13 18:05

Saranya


1 Answers

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);

Then you can set these values to your controls.

like image 56
Semih Yagcioglu Avatar answered Nov 02 '22 22:11

Semih Yagcioglu