Back to Devexpress

ASPxListEdit.SelectedIndex Property

aspnet-devexpress-dot-web-dot-aspxlistedit-f4181408.md

latest6.1 KB
Original Source

ASPxListEdit.SelectedIndex Property

Specifies the selected list item’s index.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
[DefaultValue(-1)]
public int SelectedIndex { get; set; }
vb
<DefaultValue(-1)>
Public Property SelectedIndex As Integer

Property Value

TypeDefaultDescription
Int32-1

The zero-based index of the selected list item. -1 if no item is selected within the list editor.

|

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.

csharp
protected void ASPxListBoxInstance_Init(object sender, EventArgs e) {  
    DevExpress.Web.ASPxEditors.ASPxListBox cmb = (DevExpress.Web.ASPxEditors.ASPxListBox)sender;  
    cmb.DataSource = DATA_SOURCE;  
    cmb.DataBindItems();  
}
vb
Protected Sub ASPxListBoxInstance_Init(sender As Object, e As EventArgs)  
    Dim cmb As DevExpress.Web.ASPxEditors.ASPxListBox = DirectCast(sender, DevExpress.Web.ASPxEditors.ASPxListBox)  
    cmb.DataSource = DATA_SOURCE  
    cmb.DataBindItems()  
End Sub

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.

aspx
<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" />
javascript
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;
}

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.

web-forms-pivot-grid-change-summary-display-mode/CS/SummaryDisplayMode/Default.aspx.cs#L20

csharp
SummaryDisplayTypeGroup SelectedGroup {
    get { return (SummaryDisplayTypeGroup)(rgSummaryDisplayTypeGroups.SelectedIndex); }
}

web-forms-pivot-grid-hide-particular-rows-and-columns/CS/ASPxPivotGrid_HidingColumnsAndRows/Default.aspx.cs#L22

csharp
if (pivotGrid.DataSource == null) return;
if (ASPxRadioButtonList1.SelectedIndex == 0) return;

web-forms-pivot-grid-change-summary-display-mode/VB/SummaryDisplayMode/Default.aspx.vb#L28

vb
Get
    Return CType(rgSummaryDisplayTypeGroups.SelectedIndex, SummaryDisplayTypeGroup)
End Get

web-forms-pivot-grid-hide-particular-rows-and-columns/VB/ASPxPivotGrid_HidingColumnsAndRows/Default.aspx.vb#L24

vb
If pivotGrid.DataSource Is Nothing Then Return
If ASPxRadioButtonList1.SelectedIndex = 0 Then Return
' Iterates through all row headers.

See Also

ASPxListEdit Class

ASPxListEdit Members

DevExpress.Web Namespace