Skip to main content

Posts

c# - How to get the month name from month number

Month name from number The following asp.net c# example code demonstrate us how can we get month name from number. this examplecode also demonstrate us how can we get month name from a datetime object. bellow is the explain of example source code. We created a datetime object using DateTime.Today property. DateTime.Today property get the current date without time in the web server.DteTime.Month property gets the month number from a datetime object. so we uses the DateTime.Month property to get the month number fromtoday date that represent the current month of web server. At last we call the DateTimeFormatInfo.GetMonthName() method that returns the culture specific full name of the specified month based on theculture associated with the current DateTimeFormatInfo object. GetmonthName method require an integer type argument that represent month number. CultureInfo.DateTimeFormat property get or set a DateTimeFormatInfo that defines the cult...

c# - How to get the last day of month using a given date

DateTime get last day of month The following asp.net c# example code demonstrate us how can we get last day of a month programmaticallyat run time in an asp.net application. In this example code, we will see how can we get last day of a month froma specified DateTime object. By default, .net framework's DateTime class has no method or property to get last day of a month. So, we need to applyfew techniques to get last day of a month from a given date. At first, we need to extract the month from a given date. Thenwe need to get the last day of extracted month. We applied the following techniques to get the last day of a month; first, we add one month with the given date by usingDateTime.AddMonths() method. Then we create a new DateTime variable by using the month added DateTime object's year, monthand first day (day number 1) such as 2014/12/1(DateTime.Year/DateTime.Month/1). So, we get a new DateTime object which represent first d...

c# - How to add weeks to a DateTime object

DateTime add weeks The following asp.net c# example code demonstrate us how can we add one or more weeks with a DateTimeobject programmatically at run time in an asp.net application. By default, .net framework's DateTime Class have nomethod or property to add week with a DateTime object. So we need to go technically to add weeks with a date. We know that one week is equal to 7 days, two weeks is equal to 14 days, three weeks is equal to 21 daysand so on. .Net framework's DateTime Class DateTime.AddDays() method allow us to add specified days with a DateTimeobject. This method require to pass a parameter which hold number of days to add. So, we can use this AddDays()method to add weeks with a DateTime object. As example, if we want to add one week with a date then we can call the method as DateTime.AddDays(7) and if we want toadd three weeks with a DateTime object then we can call the method as DateTime.AddDays(21) and so on. We just ne...

How to sort DropDownList items in descending order in asp.net

DropDownList items sort order by descending DropDownList is an asp.net list web server control that allow us to select one item at a time from a drop-down-list. by default dropdownlist items are not sorted. to provide better user experience, web developer wants to create a sorted dropdownlist. the following asp.net c# example code demonstrate us how can we render a dropdownlist server control which items are descending sorted. DropDownList server control have no built in property or method to sort its items descending or ascending order. we need to apply few techniques to display a sorted dropdownlist programmatically. At first we create a generic list which data type is ListItem. now we populate the generic list from dropdownlist items collection. next we sort the list by descending order using Linq OrderByDescending() extension method. finally we clear the dropdownlist items, and repopulate the dropdownlist with the sorted generic list. now we can d...

How to add top margin to a Label in asp.net

Add top margin to a Label control The Label class Represents a label control, which displays text on a Web page. The asp.net developers can use the Label control to display text in a set location on the web page. Unlike static text, asp.net c# developers can customize the displayed text through the Text property. The following asp.net c# tutorial code demonstrates how we can add the top margin to a Label web server control. To add the top margin to a Label control, the asp.net c# developers have to apply a custom CSS style to a Label control. In the below example code, we demonstrate two ways to add the top margin to a Label web server control. The Label CssClass property gets or sets the Cascading Style Sheet (CSS) class rendered by the Web server control on the client. The CssClass property is inherited from WebControl. The CssClass property value is a String which is the CSS class rendered by the Label server control on the client. The defaul...

How to add margin to a Label in asp.net

Add margin to a Label The Label class Represents a label control, which displays text on a Web page. The asp.net developers can use the Label control to display text in a set location on the web page. Unlike static text, asp.net c# developers can customize the displayed text through the Text property. The following asp.net c# tutorial code demonstrates how we can add a margin to a Label web server control. To add a margin to a Label control, the asp.net c# developers have to apply a custom CSS style to a Label control. The Label CssClass property gets or sets the Cascading Style Sheet (CSS) class rendered by the Web server control on the client. The CssClass property is inherited from WebControl. The CssClass property value is a String which is the CSS class rendered by the Label server control on the client. The default value of this property is Empty. So finally, using this CssClass property the asp.net c# developers can add a margin to ...

How to justify the text in a Label in asp.net

Justify text in a Label control The Label class Represents a label control, which displays text on a Web page. The asp.net developers can use the Label control to display text in a set location on the web page. Unlike static text, asp.net c# developers can customize the displayed text through the Text property. The following asp.net c# tutorial code demonstrates how we can justify the text on a Label web server control. To justify text in a Label control, the asp.net c# developers have to apply a custom CSS style to a Label control. The Label CssClass property gets or sets the Cascading Style Sheet (CSS) class rendered by the Web server control on the client. The CssClass property is inherited from WebControl. The CssClass property value is a String which is the CSS class rendered by the Label server control on the client. The default value of this property is Empty. So using this CssClass property the asp.net c# developers can justify tex...