Skip to main content

Posts

Showing posts with the label listbox

How to use ListBox SelectedIndexChanged event in asp.net c#

ListBox SelectedIndexChanged Event ListBox is an asp.net list web server control that contains a list of selectable items. More than one item is visible in ListBox control. ListBox SelectionMode property determines whether multiple items in the ListBox are selectable at a time. ListBox SelectedIndexChanged event occurs when the SelectedIndex property or the SelectedIndices collection has changed. ListBox SelectedIndex property gets or sets the zero-based index of the currently selected item. And SelectedIndices property gets a collection that contains the zero-based indexes of all currently selected items in ListBox. For multiple selections, the ListBox SelectedIndices property returns a collection containing the indexes of all selected items. ListBox SelectedIndexChanged event works when we set the ListBox AutoPostBack property value to True and write an event handler for the OnSelectedIndexChanged property. when a user changes the sele...

How to find ListBox item by text in asp.net c#

Find ListBox Item By Text ListBox is an ASP.NET list web server control. Developers can use the ListBox control to create a single or multi-item selection list control. We can set single selection or multi-selection mode using the ListBox SelectionMode property. ListBox Items property contains all ListItem objects. ListBox can populate with items from a data source control. So a ListBox can exists many items. Each ListItem object has a Text and a Value property. Text property holds the text to display in ListBox and Value property text is associated with the ListItem object and is hidden in the web browser. The .NET C# developers can find/search a ListItem object in ListBox using the ListItem Text property value. To find an item using its Text we need to use the Items FindByText(String) method. Items FindByText() method finds an item from ListBox using its Text property string. The following C# example source code demonstrates to us how ...

How to data bind ListBox programmatically in asp.net c#

Data bind ListBox programmatically ListBox is an ASP.NET list web server control. ListBox control's items collection contains ListItem objects. We can populate a ListBox with items by declarative syntax. We can place the ListItem element between the opening and closing tags of the ListBox control to display it in the browser. ListBox server control supports data binding. To bind the ListBox control to a data source control, developers need to first create a data source such as a DataSourceControl object. DataSourceControl serves as the base class for controls that represent data sources to data-bound controls. The DataSourceControl object contains the items to display in the ListBox. Next developers can call the ListBox DataBind method to bind the data source to the ListBox. ListBox DataTextFiled and DataValueField properties specify which field in the data source to bind the Text and Value properties. After data binding, ListBox control wil...

How to add an item to ListBox programmatically in asp.net c#

Add an item (ListItem) to ListBox The following ASP.NET C# example code demonstrates to us how can we add an item to ListBox control programmatically at run time. ListBox is an ASP.NET list web server control. ListBox contains items collection. Each item of ListBox control represents a ListItem object. We can add ListItem object to ListBox control's items collection both statically and programmatically. To add an item to ListBox control programmatically, we can call the Collection Class’s Add() method. This Add() method allows us to add an item to a collection. So we can easily add an item to the ListBox control as the Items Add(ListItem) method. Because ListBox contains an items collection that supports the addition of new items. To Add an item (ListItem) to a ListBox control, first, we need to create the ListItem object. Each ListItem object has a Text property and optionally a Value property. We can also set the specified ListItem object ...

How to use ListBox in asp.net c#

ListBox Web Server Control The ListBox is an ASP.NET list web server control. ListBox control renders a list box that allows single or multiple-item selection. ListBox SelectionMode property gets or sets the selection mode of ListBox control. SelectionMode property has two possible values those are Single and Multiple. ASP.NET developers can programmatically change the ListBox selection mode by setting the ListSelectionMode enumeration value. Multiple modes specify that multiple items can be selected from ListBox control. ListBox Row property gets or sets the number of rows displayed in ListBox. That means the Row property specifies the height of ListBox control. ListBox has an Item collection that contains all ListItem objects. each ListItem object represents an item in ListBox control. We can add or remove ListItem programmatically at run time in ListBox. We can populate a ListBox with items at design time using declarative syntax by p...