ListEditItem Class
A list item.
Namespace: DevExpress.Web
Assembly: DevExpress.Web.v24.1.dll
NuGet Package: DevExpress.Web
Declaration
Related API Members
The following members return ListEditItem objects:
Remarks
The ListEditItem class implements the item functionality of a list editor (for instance, the ASPxListBox, ASPxRadioButtonList, or ASPxComboBox).
The ListEditItemCollection collection contains instances of the ListEditItem object. To access this collection, use the Items property (for instance, the ASPxListEdit.Items and ASPxAutoCompleteBoxBase.Items properties).
Create an Item
Add a ListEditItem object to the ListEditItemCollection collection and specify item characteristics:
ListEditItem.Value - Specifies the item’s value.
ListEditItem.Text - Specifies the item’s text.
ListEditItem.ImageUrl - Specifies the item’s image.
Design Time
<dx:ASPxComboBox ID="ASPxComboBox1" runat="server">
<Items>
<dx:ListEditItem Text="Alexandra Camino" Value="1" />
<dx:ListEditItem Text="Alexander Feuer" Value="2" />
<dx:ListEditItem Text="Ana Trujillo" Value="3" />
</Items>
</dx:ASPxComboBox>
Run Time
using DevExpress.Web;
//...
protected void Page_Load(object sender, EventArgs e) {
ASPxComboBox cb = new ASPxComboBox();
cb.ID = "ASPxComboBox1";
formLayoutDetails.Controls.Add(cb);
// Add items to the drop-down list.
cb.Items.Add("Alexandra Camino", "1");
cb.Items.Add("Alexander Feuer", "2");
cb.Items.Add("Ana Trujillo", "3");
}
Access an Item
Use the Item[Int32] property to access an individual item by its index in the item collection.
ListEditItem a = combobox.Items[0];
Add a New Item to the Data Source
You can populate the data source with new items at run time.
Follow the steps below to add an item to the data source:
Handle the client-side TextChanged event. If you enter a new item, the control sends a callback to the server with the typed text as a parameter.
function onTextChanged(s, e) { if (s.GetSelectedIndex() == -1) { s.PerformCallback(s.GetText()); } }
Handle the server-side ASPxAutoCompleteBoxBase.Callback event raised by the PerformCallback method.
This event handler executes the following actions:
Gets the entered text.
Checks to ensure the data source does not have an item with the same text.
Inserts a new item into the specified data source field.
protected void ASPxComboBox1_Callback(object sender, DevExpress.Web.CallbackEventArgsBase e) { // Get the entered text. string text = e.Parameter; // Insert a new item to the data source. if (ASPxComboBox1.Items.FindByText(text) == null) { SqlDataSource.InsertParameters["CompanyName"].DefaultValue = text; SqlDataSource.Insert(); // Bind the control to the updated data source. ASPxComboBox1.DataBind(); } // Set the selected item. ASPxComboBox1.SelectedItem = ASPxComboBox1.Items.LastOrDefault(); }
Set the EnableViewState property to
false
. In this mode, the control does not maintain its view state.<dx:ASPxComboBox ID="ASPxComboBox1" runat="server" TextField="CompanyName" DropDownStyle="DropDown" OnCallback="ASPxComboBox1_Callback" DataSourceID="SqlDataSource" EnableViewState="false"> <ClientSideEvents TextChanged="onTextChanged" /> </dx:ASPxComboBox>