Monday, June 22, 2009

Tuesday, June 9, 2009

Load Years and Month to Drop down list Easely C#

public void LoadDDLYears(DropDownList ddlYear)
{
for (int i = 30; i > -30; i--)
{
ddlYear.Items.Add(System.DateTime.Now.AddYears(i).Year.ToString());
}
ddlYear.SelectedValue = System.DateTime.Now.Year.ToString();
}

public void LoadMonth(DropDownList ddlMonth)
{
DateTimeFormatInfo dtfi = new DateTimeFormatInfo();
for (int month = 1; month < 13; month++)
{
ListItem li = new ListItem();
li.Text = dtfi.GetMonthName(month);
li.Value = month.ToString();
ddlMonth.Items.Add(li);
}
}

Monday, June 8, 2009

Using regular expression for the time format validation

public bool IsValidTime(string thetime)
{
string reg=@"([0-1]\d|2[0-3]):([0-5]\d)";
Regex checktime = new Regex(@reg);

//Regex checktime = new Regex(@"^(20|21|22|23|[01]d|d)(([:][0-5]d){1,2})$");

return checktime.IsMatch(thetime);
}