Este artículo se tradujo de forma manual. Mueva el puntero sobre las frases del artículo para ver el texto original.
Traducción
Original
Este tema aún no ha recibido ninguna valoración - Valorar este tema

DropDownList.SelectedIndex (Propiedad)

Obtiene o establece el índice del elemento seleccionado del control DropDownList.

Espacio de nombres:  System.Web.UI.WebControls
Ensamblado:  System.Web (en System.Web.dll)
public override int SelectedIndex { get; set; }
<asp:DropDownList SelectedIndex="Int32" />

Valor de propiedad

Tipo: System.Int32
Índice del elemento seleccionado del control DropDownList. El valor predeterminado es 0, que selecciona el primer elemento de la lista.

Utilice la propiedad SelectedIndex para especificar o determinar mediante programación el índice del elemento seleccionado del control DropDownList. Siempre hay un elemento seleccionado en el control DropDownList. No puede cancelar la selección de todos los elementos de la lista a la vez.

Nota Nota

Los índices de los elementos del control DropDownList están basados en cero.

En el siguiente ejemplo se muestra cómo usar la propiedad SelectedIndex para determinar el elemento seleccionado del control DropDownList.


<%@ Page Language="C#" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
   <script runat="server" >

      void Selection_Change(Object sender, EventArgs e)
      {

         // Set the title format based on the value selected from the
         // DropDownList control. The SelectedIndex property can be used
         // to determine an enumeration value. Simply cast the value to 
         // the appropriate enumeration type. Note that the value might
         // need to be adjusted if the enumeration type is not zero-based. 
         Calendar1.TitleFormat = (TitleFormat)ModeList.SelectedIndex;

      }

   </script>

<head runat="server">
    <title> DropDownList SelectedIndex Example </title>
</head>
<body>

   <form id="form1" runat="server">

      <h3> DropDownList SelectedIndex Example </h3>

      Choose the title format.

      <br /><br /> 

      <asp:Calendar id="Calendar1"
           ShowGridLines="True" 
           ShowTitle="True"
           runat="server"/>

      <br /><br />

      <table cellpadding="5">

         <tr>

            <td>

               Format:

            </td>

         </tr>

         <tr>

            <td>

               <asp:DropDownList id="ModeList"
                    AutoPostBack="True"
                    OnSelectedIndexChanged="Selection_Change"
                    runat="server">

                  <asp:ListItem> Month </asp:ListItem>
                  <asp:ListItem Selected="True"> MonthYear </asp:ListItem>

               </asp:DropDownList>

            </td>

         </tr>

      </table>   

   </form>

</body>
</html>
 


.NET Framework

Compatible con: 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 7, Windows Vista SP1 o posterior, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (no se admite Server Core), Windows Server 2008 R2 (se admite Server Core con SP1 o posterior), Windows Server 2003 SP2

.NET Framework no admite todas las versiones de todas las plataformas. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.
¿Le ha resultado útil?
(Caracteres restantes: 1500)
Contenido de la comunidad Agregar