protected void cmbOrganization_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e) { txtFirstDay2.Text = GetFirstDayOfMonth(cmbOrganization.SelectedIndex + 1).ToShortDateString(); // get day of week for first day //string[] dateParts = txtFirstDay2.Text.Split('/'); //DateTime dtFirstTemp = new // DateTime(Convert.ToInt32(dateParts[2]), // Convert.ToInt32(dateParts[0]), // Convert.ToInt32(dateParts[1])); // display day of week in label //lblDowFirst2.Text = dtFirstTemp.DayOfWeek.ToString(); // set last day txtLastDay2.Text = GetLastDayOfMonth(cmbOrganization.SelectedIndex + 1).ToShortDateString(); // get day of week for last day //string[] dateParts2 = txtLastDay2.Text.Split('/'); //DateTime dtLastTemp = new // DateTime(Convert.ToInt32(dateParts2[2]), // Convert.ToInt32(dateParts2[0]), // Convert.ToInt32(dateParts2[1])); // display day of week in label //lblDowList2.Text = dtLastTemp.DayOfWeek.ToString(); //DateTime dt = new DateTime(dtpDate.Value.Year, // dtpDate.Value.Month, 1); } #region Private Methods /// <summary> /// Get the first day of the month for /// any full date submitted /// </summary> /// <param name="dtDate"></param> /// <returns></returns> private DateTime GetFirstDayOfMonth(DateTime dtDate) { // set return value to the first day of the month // for any date passed in to the method // create a datetime variable set to the passed in date DateTime dtFrom = dtDate; // remove all of the days in the month // except the first day and set the // variable to hold that date dtFrom = dtFrom.AddDays(-(dtFrom.Day - 1)); // return the first day of the month return dtFrom; } /// <summary> /// Get the first day of the month for a /// month passed by it's integer value /// </summary> /// <param name="iMonth"></param> /// <returns></returns> private DateTime GetFirstDayOfMonth(int iMonth) { // set return value to the last day of the month // for any date passed in to the method // create a datetime variable set to the passed in date DateTime dtFrom = new DateTime(DateTime.Now.Year, iMonth, 1); // remove all of the days in the month // except the first day and set the // variable to hold that date dtFrom = dtFrom.AddDays(-(dtFrom.Day - 1)); // return the first day of the month return dtFrom; } /// <summary> /// Get the last day of the month for any /// full date /// </summary> /// <param name="dtDate"></param> /// <returns></returns> private DateTime GetLastDayOfMonth(DateTime dtDate) { // set return value to the last day of the month // for any date passed in to the method // create a datetime variable set to the passed in date DateTime dtTo = dtDate; // overshoot the date by a month dtTo = dtTo.AddMonths(1); // remove all of the days in the next month // to get bumped down to the last day of the // previous month dtTo = dtTo.AddDays(-(dtTo.Day)); // return the last day of the month return dtTo; } /// <summary> /// Get the last day of a month expressed by it's /// integer value /// </summary> /// <param name="iMonth"></param> /// <returns></returns> private DateTime GetLastDayOfMonth(int iMonth) { // set return value to the last day of the month // for any date passed in to the method // create a datetime variable set to the passed in date DateTime dtTo = new DateTime(DateTime.Now.Year, iMonth, 1); // overshoot the date by a month dtTo = dtTo.AddMonths(1); // remove all of the days in the next month // to get bumped down to the last day of the // previous month dtTo = dtTo.AddDays(-(dtTo.Day)); // return the last day of the month return dtTo; }
<telerik:RadComboBox ID="cmbOrganization" Runat="server" AllowCustomText="True" AutoPostBack="True" onselectedindexchanged="cmbOrganization_SelectedIndexChanged"> <Items> <telerik:RadComboBoxItem runat="server" Text="January" Value="January" /> <telerik:RadComboBoxItem runat="server" Text="February" Value="February" /> <telerik:RadComboBoxItem runat="server" Text="March" Value="March" /> </Items> </telerik:RadComboBox>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)