Skip to main content

Posts

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...

How to trim text with ellipsis in a Label in asp.net

Trim text with ellipsis on 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 trim a text with an ellipsis and display it on a Label web server control. To show an ellipsis on 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 propert...

How to display html tags in a Label in asp.net

Show HTML tags on 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 display HTML tags in a Label web server control. To show HTML tags on a Label control, the asp.net c# developers have to encode HTML tags. The Server HTMLEncode() method applies HTML encoding to a specified string. The HTMLEncode() method is very useful and a quick method of encoding form data and other client request data before using it in a Web application. Encoding data converts potentially unsafe characters to their HTML-encoded equivalent. The Server HTMLEncode() method has a parameter named string which specifies the string to encode. The Server HTMLEncode() method ha...

How to add an onClick event to a Label in asp.net

Add an onClick event 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 an onClick event to a Label web server control. But there is no built-in onClick event in the Label control. So we have to find an alternate solution to attach a click event to a Label control. In the below asp.net c# code, we used the Label control’s Attributes property to add a click event to a Label web server control. The Attributes property allows us to add a javascript click event to a Label server control. The Label Attributes property gets the collection of arbitrary attributes (for rendering only) that do not correspond to properties on the control. This p...