ASPxListEdit.SelectedIndex Property
Specifies the selected list item’s index.
Namespace: DevExpress.Web
Assembly: DevExpress.Web.v24.2.dll
Declaration
Property Value
Type | Default | Description |
---|---|---|
Int32 | -1 | The zero-based index of the selected list item. |
Remarks
Use the SelectedIndex
property to move selection within the list editor. You can also change the selected item via the ASPxListEdit.SelectedItem property.
Handle the ASPxListEdit.SelectedIndexChanged event to respond to the selection being changed within the list editor.
If you bind (populate the Item
collection) at runtime, make sure that you perform this operation during each round trip to the server in the control’s Init
or Page_Init
event. Otherwise, the SelectedIndex
property may return -1
.
protected void ASPxListBoxInstance_Init(object sender, EventArgs e) {
DevExpress.Web.ASPxEditors.ASPxListBox cmb = (DevExpress.Web.ASPxEditors.ASPxListBox)sender;
cmb.DataSource = DATA_SOURCE;
cmb.DataBindItems();
}
For more information, refer to the following property description: EnableSynchronization
Example
This example demonstrates how the ASPxSpinEdit‘s decimal separator is automatically changed upon selecting a culture.
<asp:Label ID="Label1" runat="server" Text="Culture: " AssociatedControlID="ASPxRadioButtonList1"/>
<dx:ASPxRadioButtonList ID="ASPxRadioButtonList1" runat="server" SelectedIndex="0">
<Items>
<dx:ListEditItem Text="English (USA)" Value="en-US" />
<dx:ListEditItem Text="Italian" Value="it-IT" />
</Items>
<ClientSideEvents SelectedIndexChanged="function(s, e) {
document.location.href = "?culture=" + s.GetSelectedItem().value;
}" />
</dx:ASPxRadioButtonList>
<dx:ASPxSpinEdit ID="ASPxSpinEdit1" runat="server" Number="0.1" />
protected void Page_Load(object sender, EventArgs e) {
ASPxRadioButtonList1.SelectedIndex = GetCulture() == "en-US" ? 0 : 1;
}
protected override void InitializeCulture() {
base.InitializeCulture();
CultureInfo ci = new CultureInfo(GetCulture(), true);
System.Threading.Thread.CurrentThread.CurrentCulture = ci;
System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
}
private string GetCulture() {
string culture = "en-US";
if (!string.IsNullOrEmpty(Page.Request.Params["culture"]))
culture = Page.Request.Params["culture"];
int comma = culture.IndexOf(",");
if (comma != -1)
culture = culture.Remove(comma);
return culture;
}
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the SelectedIndex property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.