Skip to main content

Posts

Showing posts with the label dropdownlist

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

asp.net - How to find an item by value from a DropDownList

DropDownList FindByValue(String) Method DropDownList server control creates a single selection drop-down-list control. Asp.net developers can place ListItem objects between opening and closing tags of DropDownList control to specify list items. Each ListItem object represents a single item in DropDownList. Developers also can populate a DropDownList with items by using various data source controls such as SqlDataSource, LinqDataSource, ObjectDataSource, etc. ListItem represents a data item in DropDownList control. ListItem Text property gets or sets the text displayed in DropDownList and the Value property gets or sets the value associated with the ListItem. Value is hidden in the browser. We can find ListItem from a DropDownList Items collection programmatically by the specific ListItem value. DropDownList Items property gets the collection of items in DropDownList. The .net ListItemCollection class’s FindByValue() method searches a ListItem...

asp.net - How to find an item by text in a DropDownList

DropDownList.Items.FindByText(String) Method DropDownList represents a control that allows the user to select a single item from a drop-down list. The .NET developers can populate a DropDownList control by items using data bind with a data source control. They also can specify DropDownList items by placing ListItem objects between opening and closing DropDownList tags using declarative syntax. ListItem object has a Text property that gets or sets the text displayed in DropDownList. And have a Value property that is associated with the ListItem. Value property value is hidden in the web browser. We can find a DropDownList item by its Text property programmatically at run time. The .NET ListItemCollection class’s FindByText() method searches the item collection for a ListItem with a Text property that equals the specified text. This method is case-sensitive and culture-insensitive. The null is returned if this method does not find an item. ...

How to use DropDownList AutoPostBack in asp.net c#

DropDownList AutoPostBack Feature DropDownList control allows users to select an item from a single selection drop-down list. We can specify DropDownList items by placing ListItem elements between the opening and closing tags of the DropDownList control. The .NET developers can also populate DropDownList from a data source object such as SqlDataSource, ObjectDataSource, LinqDataSource, ArrayList, Array, etc. The DropDownList DataBind method binds the data source to the DropDownList control. Users can select an item from DropDownList and manually submit the form using submit button to send their selection to the server. This way we can get user selection by clicking a submit button. But ASP.NET DropDownList is a more user-friendly server control. It has a property name AutoPostBack. AutoPostBack property works with the SelectedIndexChanged event. AutoPostBack property gets or sets a value that indicates whether a postback to the server au...

asp.net - How to data bind a DropDownList with an array

DataBind DropDownList with array The following asp.net c# example code demonstrates to us how can we populate a DropDownList server control with items from an Array data source. DropDownList is a list web server control. DropDownList can contain one or more ListItem objects. A ListItem object includes Text and an optional Value. The Array is the most preferable data source for .NET developers to populate a list server control. In this example code, we initialized a String data type Array object with items/elements. Then we set the DropDownList's DataSource property value to the newly initialized Array object. Next, we call the DropDownList DataBind() method to data bind DropDownList with the Array data source. Each element of the Array creates an item in DropDownList. This is a one-dimensional Array, so DropDownList's each ListItem object's 'Text' and 'Value' properties hold the same value; such as if Array'...