Latest web development tutorials

ASP.NET SortedList

objetos SortedList combina las propiedades de un objeto y el objeto ArrayList Hashtable.


Ejemplos

Trate - Ejemplo

SortedList RadioButtonList 1

SortedList RadioButtonList 2

SortedList DropDownList


objetos SortedList

SortedList objeto contiene elementos con la tecla / pares de valores expresados. SortedList clasificar objetos automáticamente los elementos en orden alfabético o numérico.

Por método Add () para añadir elementos a la SortedList. Por el método TrimToSize () para ajustar el tamaño final SortedList.

El siguiente código crea un objeto denominado SortedList mycountries, y añadir los cuatro elementos:

<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New SortedList
mycountries.Add("N","Norway")
mycountries.Add("S","Sweden")
mycountries.Add("F","France")
mycountries.Add("I","Italy")
end if
end sub
</script>


Los datos de unión

SortedList objeto puede generar automáticamente el texto y los valores de los controles siguientes:

  • asp: RadioButtonList
  • asp: CheckBoxList
  • asp: DropDownList
  • asp: Cuadro de lista

Para enlazar datos a un control RadioButtonList, en primer lugar crear un control RadioButtonList en una página .aspx (sin asp: elementos ListItem):

<html>
<body>

<form runat="server">
<asp:RadioButtonList id="rb" runat="server" AutoPostBack="True" />
</form>

</body>
</html>

A continuación, añadir el script para crear la lista, y los valores de unión en la lista para el control RadioButtonList:

<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New SortedList
mycountries.Add("N","Norway")
mycountries.Add("S","Sweden")
mycountries.Add("F","France")
mycountries.Add("I","Italy")
rb.DataSource=mycountries
rb.DataValueField="Key"
rb.DataTextField="Value"
rb.DataBind()
end if
end sub
</script>

<html>
<body>

<form runat="server">
<asp:RadioButtonList id="rb" runat="server" AutoPostBack="True" />
</form>

</body>
</html>

A continuación, añadimos una subrutina, cuando un usuario hace clic en un elemento en el control RadioButtonList cuando se ejecuta la subrutina. Cuando se hace clic en un botón de opción, la etiqueta aparecerá en la línea de texto:

Ejemplos

<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New SortedList
mycountries.Add("N","Norway")
mycountries.Add("S","Sweden")
mycountries.Add("F","France")
mycountries.Add("I","Italy")
rb.DataSource=mycountries
rb.DataValueField="Key"
rb.DataTextField="Value"
rb.DataBind()
end if
end sub

sub displayMessage(s as Object,e As EventArgs)
lbl1.text="Your favorite country is: " & rb.SelectedItem.Text
end sub
</script>

<html>
<body>

<form runat="server">
<asp:RadioButtonList id="rb" runat="server"
AutoPostBack="True" onSelectedIndexChanged="displayMessage" />
<p><asp:label id="lbl1" runat="server" /></p>
</form>

</body>
</html>

La demostración >>