ASP.NET SortedList
objetos SortedList combina as propriedades de um objeto eo objeto ArrayList Hashtable.
Tente - Exemplo
objetos SortedList
objeto SortedList contém itens com a chave / valor pares expressa. SortedList objetos classificar automaticamente os itens em ordem alfabética ou numérica.
Pelo método add () para adicionar itens para o SortedList. Pelo método TrimToSize () para ajustar o tamanho final SortedList.
O código a seguir cria um objeto SortedList chamado mycountries, e adicionar os quatro elementos:
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>
Ligação de dados
SortedList objeto pode gerar automaticamente texto e valores para os seguintes controles:
- asp: RadioButtonList
- asp: CheckBoxList
- asp: DropDownList
- asp: Listbox
Para vincular dados a um controle RadioButtonList, primeiro crie um controle RadioButtonList em uma página .aspx (sem qualquer asp: ListItem elementos):
<body>
<form runat="server">
<asp:RadioButtonList id="rb" runat="server" AutoPostBack="True" />
</form>
</body>
</html>
Em seguida, adicione o script para criar a lista e os valores de ligação na lista para o controle RadioButtonList:
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>
Em seguida, adicionar uma sub-rotina, quando um usuário clica em um item no controle RadioButtonList quando a sub-rotina é executada. Quando um botão de opção é clicado, etiqueta aparecerá na linha de texto:
Exemplos
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>
A demonstração >>