Table of Contents
- Getting Started
- EO.Pdf
- EO.Web
- Overview
- Installation & Deployement
- EO.Web ToolTip
- EO.Web Rating
- EO.Web Slider & RangeSlider
- EO.Web ListBox
- EO.Web ComboBox
- EO.Web Captcha
- EO.Web ASPX To PDF
- EO.Web Slide
- EO.Web Flyout
- EO.Web EditableLabel
- EO.Web ImageZoom
- EO.Web Floater
- EO.Web Downloader
- EO.Web ColorPicker
- EO.Web HTML Editor
- EO.Web File Explorer
- EO.Web SpellChecker
- EO.Web Grid
- EO.Web MaskedEdit
- EO.Web Splitter
- EO.Web Menu
- EO.Web Slide Menu
- EO.Web TabStrip
- EO.Web TreeView
- EO.Web Calendar
- EO.Web Callback
- EO.Web MultiPage
- EO.Web Dialog
- EO.Web AJAXUploader
- EO.Web ProgressBar - Free!
- EO.Web ToolBar - Free!
- EO.WebBrowser
- EO.Wpf
- Common Topics
- Reference
Configure List Items |
EO.Web ListBox items can be statically declared in .aspx file or programmatically created either through data binding or through code directly.
Statically Declare Items In .aspx file
To statically declare items in .aspx file, simply add one or more ListBoxItem object into the ListBox's Items collection:
<eo:ListBox ....> .... <Items> <eo:ListBoxItem Text="Item 1" /> <eo:ListBoxItem Text="Item 2" /> <eo:ListBoxItem Text="Item 3" /> </Items> .... </eo:ListBox>
Creating Items Dynamically through Code
To dynamically create items through code, you can create one or more ListBoxItem object, then add them into ListBox's Items collection:
//Create a new item EO.Web.ListBoxItem item = new EO.Web.ListBoxItem("Item 1"); //Add the new item into the ListBox ListBox1.Items.Add(item);
Using ItemTemplate
You can use ItemTemplate to customize the content of each item. The following code displays the item text in bold:
<eo:ListBox ....> .... <ItemTemplate> <b><%#Container.Item.Text%></b> </ItemTemplate> <Items> <eo:ListBoxItem Text="Item 1" /> <eo:ListBoxItem Text="Item 2" /> <eo:ListBoxItem Text="Item 3" /> </Items> </eo:ListBox>
In the above data binding expression, Container is a ListBoxItemContainer object.
Creating Items through Data Binding
To create items through data binding, you can set the ListBox's DataSource, then call its DataBind method. For example,
//Set the data source to a string array ListBox1.DataSource = new string[]{"Item 1", "Item 2", "Item 3"}; //Call DataBind to create the items ListBox1.DataBind();
Data binding is often used together with ItemTemplate. For example, the following ItemTemplate simply uses each item data (string) as item text:
<ItemTemplate> <%#Container.Item.DataItem%> </ItemTemplate>
DataBind can be called inside MoreItemsNeeded event. When called inside this event, DataBind automatically operates in "append" mode. That is, it only appends new items. For example, if the ListBox already have 20 items and the data source has 10 items, the DataBind would create 10 new items based on the data source and append these 10 items to the ListBox, thus having 30 items in total after the call. If DataBind is called outside of MoreItemsNeeded event, it would clear the existing 20 items first, thus having 10 items in total after the call.