Skip to main content

Posts

Showing posts with the label Medium Content

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

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

c# - How to remove non alphanumeric characters from a string

String remove non alphanumeric The following asp.net c# example code demonstrate us how can we remove non alphanumeric charactersprogrammatically at run time from a string object. So, we keep only alphabet (letter) (a to z) and numeric characters(0 to 9). .Net framework's String class has no built in method or property to remove non alphanumeric charactersfrom a string value. To remove non alphanumeric characters from a string object, first we need to convert the string value to a char array.String.ToCharArray() copies the characters in this instance to a Unicode character array. Next, we need to loop through thechar array elements. In this example, we loop char array elements by using foreach loop. Finally, we can test, which character is alphanumeric or not. We can determine a character's alphanumeric stateby using Char.IsLetterOrDigit() method. The Char.IsLetterOrDigit(Char) overloaded method indicate whether a Unicode characteris c...

c# - How to remove a substring from a string

String remove substring The following asp.net c# example code demonstrate us how can we remove a substring from a string programmatically at run timein an asp.net application. .Net framework's String.Remove() method allow us to remove specified characters (range of characters)from a string and return a new string object. String.Remove(Int32, Int32) overloaded member allow us to return a new string in which a specified number of characters in thecurrent instance beginning at a specified index position have been deleted. So, we can delete specified number of charactersfrom a string which are beginning at a specified index position. So, to delete a substring from a string, we need to know the starting index value of this substring and the length of thissubstring (number of characters in substring). String.IndexOf(String) overloaded method reports the zero-based index of the first occurrence of the specified string in thisinstance. Strin...

c# - How to find first index of a character within a string

Find index of character in string The following asp.net c# example code demonstrate us how can we find index of a specified character in a stringprogrammatically at run time in an asp.net application. .Net framework's String Class represent Text as a series of UnicodeCharacters. String Class String.IndexOf(Char) overloaded method reports the zero-based index of the first occurrence of the specified Unicode characterin this string. String.IndexOf(Char) method has a required parameter named 'value' which data type is System.Char. This parameter valuerepresent a Unicode character to seek. String.IndexOf(Char) method return a System.Int32 data type integer value. This return value represent the zero-based index position ofspecified character, if that character is found; otherwise it return -1. So, we can find index of a character from a string using String.IndexOf(Char) method. We just need to call the method andspecify the strin...

c# - String startswith case insensitive

String startswith case insensitive The following asp.net c# example code demonstrate us how can we determine whether a string starts with a specifiedsubstring (string comparison is ignoring case) programmatically at run time in an asp.net application. .Net framework's String Class String.StartsWith(String, StringComparison) overloaded method can determine whether thebeginning of this string instance matches the specified string when compared using the specified comparison option. String.StartsWith(String, StringComparison) method has two required parameters named 'value' and 'comparisonType'. The 'value' parameterrepresent the string to compare. The 'comparisonType' parameter value type is 'System.StringComparison' which represent one of the enumerationvalues that determines how this string and specified string (value parameter) are compared. System.StringComparison enumeration value 'Ordinal...

c# - How to escape double quotes in a string

String escape double quote The following asp.net c# example code demonstrate us how can we escape double quote in a string programmaticallyat run time in an asp.net application. .Net framework's String Class represent text as a series of Unicode characters.We can escape double quotes (") in a string by several ways. We can escape double quotes in a string by using a escape character Backslash (\). If we want to include a doublequotes in this way, we should write the string as ("a \"sample\" text"). Here the word (sample) will be surrounded by twodouble quotes as "sample". We also can escape double quotes in a string object by using @ symbol. If we want to write the same string in this technique,then we should format it as (@"a ""sample"" text"). Here we also need to place a double quotes two times to get output a single doublequotes. Both techniques show the same output. ...

c# - How to apply padding on a StringBuilder

c# example - stringbuilder padding padleft padright The following asp.net c# example code demonstrate us how can we apply padding on StringBuilder value programmatically at run time in an asp.netapplication. In .net framework's StringBuilder Class represent a mutable string of characters. StringBuilder Class has no built in method or property to apply padding on it's text. But String Class has twobuilt in methods to padding its content. We can use StringBuilder.ToString() methodto directly convert a StringBuilder value to a System.String object. String Class has two methods two padding it's content, those are PadLeft() and PadRight(). Both methods has overload. String Class PaLeft(Int32, Char) overloaded method return a new string that right-aligns the characters in this instance by padding them onthe left with a specified Unicode character, for a specified total length. So, we can specify number of times the specified cha...

c# - How to check if a StringBuilder is empty

c# example - stringbuilder check if empty The following ASP.NET C# example code demonstrate us how can we determine whether a Stringbuilder objectis empty or contain any characters. .Net framework's StringBuilder Class represent a mutable string of characters.StringBuilder class cannot be inherited. StringBuilder and String both objects represent sequences of characters, but they are implemented differently. String is animmutable type and StringBuilder is a mutable type. So, each operation that appears to modify a String object actuallycreate and return a new String but each operation to modify a StringBuilder object return the same StringBuilder objectas modified. .Net framework's StringBuilder.Length property allow us to get the length of the current Stringbuilder object. This propertyreturn a System.Int32 value. Returned integer value represent the length of StringBuilder instance. So, we can check whether a StringBuilder obj...

c# - How to check whether an element exists in an array

Array exists The following asp.net c# example code demonstrate us how can we determine whether specified elements are exists in anarray based on search criteria. .Net framework's Array Class Array.Exists<T>() method allow us to determine whetherthe specified array contains one or more elements that match the conditions defined by the specified predicate. Array.Exists<T>() method type parameter is 't' which represent the type of the elements of the array. This method hastwo required parameters named 'array' and 'match'. The 'array' parameter represent the one-dimensional, zero-based index array tosearch. The 'match' parameter value represent the Predicate<T> that defines the conditions of the elements to search for. Array.Exists() method return a Boolean value. It return 'true', if array contains value that match the condition; otherwiseit return 'false'. In this ...

c# - How to convert Dictionary keys into array

How to convert Dictionary Keys into array .Net framework Dictionary<TKey, TValue> class represents a collection of keys and values. the Dictionary<TKey, TValue>.Keysproperty allow us to get a collection containing the keys in the Dictionary<TKey, TValue>. this Keys property value type isSystem.Collections.Generic.Dictionary<TKey, TValue>.KeyCollection. to convert a dictionary keys to array, first we need to get the dictionary keys by its 'Keys' property. this property return acollection (generic list) of dictionary keys. after getting the List<T>, we can convert it to an array by List class ToArray() method. List<T>.ToArray() method allow us to copy the elements of the List<T> to a new array. so we can convert the dictionary keys into array asDictionary<TKey, TValue>.Keys.ToArray(). the following asp.net c# example code demonstrate us how can we convert dictionary keys to an array ...

asp.net - How to use Calendar SelectionChanged event

How to use Calendar SelectionChanged event in asp.net Calendar is an asp.net rich web server control. calendar control displays the dates for one month at a time. total six weeksappearing at the same time. users can select an individual date from calendar control. even users can select multiple dates (date range)from a calendar server control. calendar SelectionChanged event occurs when the users select an individual date or range of dates. by using this event we can determinewhat date or dates the user has selected. we can write an event handler for calendar SelectionChanged event to display user selecteddate or dates in web page after postback. to get the calendar selected dates we loop through the calendar SelectedDates collection using for loop and display the selected date liston web page. the following asp.net c# example code demonstrate us how can we use the calendar SelectionChanged event in an asp.net application. Calenda...

c# - How to filter data in a DataView

DataView RowFilter Property .Net framework's DataView represents a data bindable, customized view of a DataTable for sorting, searching, filtering, navigation, and editing. DataView represents a connected view of its corresponding DataTable. DataView does not stroe data. If we change the DataView data, it will affect the DataTable. If we change the DataTable's data, it will affect all associated DataViews. DataView class exists in System.Data namespace. DataView class’s RowFilter property allows us to get or set the expression used to filter which rows are viewed in the DataView. RowFilter property value data type is String which represents a String that specifies how rows are to be filtered. We can assign a RowFilter value as "FirstName = 'Innee'" where 'FirstName' is a column name followed by an operator (=) and a value 'Innee' to filter on. The value must be in quotation marks. The followi...

c# - How to count rows in a DataView

DataView Count Property .NET framework's DataView represents a data bindable, customized view of a DataTable for sorting, searching, filtering, navigation, and editing. The DataView object does not store data but it represents a connected view of its corresponding DataTable. DataView RowFilter property allows us to get or set the expression used to filter which rows are viewed in the DataTable. DataView RowStateFilter property allows us to get or set the row state filter used in the DataView. The DataView Count property allows us to get the number of records (rows) in a DataTable after RowFilter and RowStateFilter have been applied. The Count property value data type is an Int32. This integer value represents the number of records in the DataView. The Count property implements as ICollection.Count. The following ADO.NET C# example code demonstrates to us how can we count a DataView's rows (records) programmatically at run time in...

How to use TextBoxWatermarkExtender in asp.net ajax

TextBoxWatermarkExtender TextBoxWatermarkExtender is an asp.net ajax control toolkit's extender control. TextBoxWatermarkExtender control can be attached to an asp.net TextBox web server control. TextBoxWatermarkExtender control apply watermark behavior on target TextBox server control. When a watermarked textbox control is empty, it display a message in the text input area of the textbox with a custom css style. if someone typed some text into the textbox control, the watermarked appearance goes away. TextBoxWatermarkExtender control's properties are TargetControlID, WatermarkText and WatermarkCssClass. TargetControlID property specify the TextBox server control which we want to extend for attach watermark behavior. WatermarkText property set the message which we want to display in TextBox control when textbox has no value. WatermarkCssClass represent a css class which we want to apply into the textbox control when textbox has no value. Typically...

How to use DragPanelExtender in asp.net ajax

DragPanelExtender DragPanelExtender is an asp.net ajax control toolkit's extender control. DragPanelExtender control allow asp.net developers to add draggability to thier controls. DragPanelExtender control can be attached with asp.net Panel server control. DragPanelExtender control attached with an additional control to use as the drag handle. DragPanelExtender control have the two important properties those are TargetControlID and DragHandleID. TargetControlID property specify the Panel server control which we want to make draggable. DragHandleID specify a control which will serve as the drag handle for the target Panel control. when user clicks and drags DragHandleID property specified control, the target Panel will move. The following asp.net ajax example code demonstrate us how can we use DragPanelExtender to make a draggable panel. we can use the target Panel control as a container for other controls those we want to make draggable. in this exam...

How to use PagingBulletedListExtender in asp.net ajax

PagingBulletedListExtender in asp.net ajax PagingBulletedListExtender is an asp.net ajax control toolkit's extender control. PagingBulletedListExtender control can be attached to an asp.net BulletedList web server control and provide client side sorted paging. PagingBulletedListExtender control have the following properties those are TargetControlID, ClientSort, IndexSize, MaxItemPerPage, Separator, SelectIndexCssClass and UnselectIndexCssClass. PagingBulletedListExtender control's TargetControlID property specify the BulletedList server control which we want to extend as a sorted paging bulleted list. ClientSort property specify whether extended BulletedList control's items should be sorted client side. IndexSize property set the number of characters in the index headings should be appear in extended bulltedlist control. This property is ignored if MaxItemPerPage property have a value. MaxItemPerPage property allow us to set maximum number ...

asp.net - How to show and hide a Panel programmatically

Show (visible) and hide Panel programmatically The Panel is an asp.net web server control that acts as a container control for other asp.net controls and HTML elements. Panel inside controls act as a group of controls. So we can apply common properties of the Panel's inside controls by setting the panel's properties such as showing or hiding all controls, aligning and directing controls, etc. Panel Visible property accepts a Boolean value. if we set the Panel Visible property value to false then it hides all inside controls from the web page with the Panel itself. Panel Visible property value True means the Panel and its inside controls will render in web pages and all elements are visible to visitors. We can control the Panel and its inside controls visibility using Panel's Visible property. The Visible property value True and False works as a switch to rendering or not rendering the Panel on the web page. The Panel acts as a par...

How to change menu static item hover style in asp.net c#

Static hover style in menu control The Menu is an ASP.NET web server control. Menu control's StaticHoverStyle property gets a reference to the style object that allows us to set the appearance of a static menu item when the mouse pointer is positioned over it. This property value type is System.Web.UI.WebControls.Style. This Style represents the style of a static menu item when the mouse pointer is positioned over it. The StaticHoverStyle property has a few sub-properties. we can set the property both declaratively and programmatically. The declarative syntax is Property-Subproperty and the programmatic syntax is Property.Subproperty (StaticHoverStyle.BackColor). So we can set the static menu item hover style as setting the background color, text color, border style, border width, font name, text size, etc. The following ASP.NET C# example code demonstrates to us how can we set or change the Menu control's static menu items hover style...