body { font-family: Arial, sans-serif; line-height: 1.6; margin: 0; padding: 0; color: #333; }
.container { max-width: 1200px; margin: 0 auto; padding: 20px; }
h1, h2, h3 { color: #2c3e50; }
h1 { border-bottom: 2px solid #3498db; padding-bottom: 10px; }
h2 { margin-top: 30px; }
.code-block { background-color: #f8f9fa; border: 1px solid #ddd; border-radius: 4px; padding: 15px; margin: 20px 0; overflow-x: auto; font-family: 'Courier New', monospace; }
.note { background-color: #e7f3fe; border-left: 4px solid #2196F3; padding: 12px; margin: 20px 0; }
.example-link { display: inline-block; background-color: #4CAF50; color: white; padding: 8px 16px; text-decoration: none; border-radius: 4px; margin-top: 10px; }
.example-link:hover { background-color: #45a049; }
.navigation { background-color: #f5f5f5; padding: 15px; margin-bottom: 30px; border-radius: 4px; }
.navigation ul { list-style-type: none; padding: 0; }
.navigation li { margin: 5px 0; }
.navigation a { text-decoration: none; color: #3498db; }
.navigation a:hover { text-decoration: underline; }
.property-table { width: 100%; border-collapse: collapse; margin: 20px 0; }
.property-table th, .property-table td { border: 1px solid #ddd; padding: 12px; text-align: left; }
.property-table th { background-color: #f2f2f2; }
.footer { margin-top: 50px; padding-top: 20px; border-top: 1px solid #eee; text-align: center; color: #777; }
ASP.NET SelectedIndex Property
Definition and Usage
The SelectedIndex property represents the ordinal index of the selected item in the list.
Example
The following example gets the index of a ListItem in a RadioButtonList control:
<script runat="server">
Sub Change(obj As Object, e As EventArgs)
Response.Write("Selected index: " & rb1.SelectedIndex)
End Sub
</script>
<form runat=server>
<asp:RadioButtonList id="rb1" AutoPostBack="true"
runat="server" OnSelectedIndexChanged="Change">
<asp:ListItem Text="Item 1" />
<asp:ListItem Text="Item 2" />
</asp:RadioButtonList>
</form>
Try it yourself Β»
More Examples
This property is commonly used with controls that inherit from ListControl, such as:
- ListBox
- DropDownList
- RadioButtonList
- BulletedList
Note: The index is zero-based. If no item is selected, the SelectedIndex property returns -1.
Property Values
| Value |
Description |
| Integer |
The zero-based index of the selected item. Default is 0 (first item selected). |
Related Properties
- SelectedItem - Gets the selected item object
- Items - Gets the collection of items in the list
- SelectedValue - Gets the value of the selected item