zoukankan      html  css  js  c++  java
  • SortedList 对象兼有 ArrayList 和 Hashtable 对象的特性。

    SortedList 对象

    SortedList 对象包含用键/值对表示的项目。SortedList 对象可按照字符顺序或数字顺序自动地对项目进行排序。

    通过 Add() 方法向 SortedList 添加项目。SortedList 可通过 TrimToSize() 方法调整为最终尺寸。

    下面的代码创建了一个名为 mycountries 的 SortedList,并添加了四个元素:

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

    数据绑定

    SortedList 对象可自动地为下面的控件生成文本和值:

    • asp:RadioButtonList
    • asp:CheckBoxList
    • asp:DropDownList
    • asp:Listbox

    如需把数据绑定到 RadioButtonList 控件,首先请在 aspx 文件中创建一个 RadioButtonList 控件(没有任何 asp:ListItem 元素):

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

    然后添加构建列表的脚本:

    <script runat="server">
    sub Page_Load
    if Not Page.IsPostBack then
      dim mycountries=New SortedList
      mycountries.Add("C","China")
      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>

    然后我们添加一个子例程,该子例程会在用户点击 RadioButtonList 控件中的项目时执行。当单选按钮被点击时,文本将出现在 label 中:

    <script runat="server">
    sub Page_Load
    if Not Page.IsPostBack then
      dim mycountries=New SortedList
      mycountries.Add("C","China")
      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>
  • 相关阅读:
    414. Third Maximum Number 第三大的数字
    java 正则表达式
    将含有逻辑运算符的字符串解析为逻辑符号
    ora-01830:日期格式图片在转换整个输入字符串之前结束
    mysql的字符拼接
    oracle执行计划详解
    oracle获取执行计划及优缺点 详解
    kmp算法中的nextval实例解释
    kmp算法中的next数组实例解释
    哈夫曼实例解释(哈夫曼编码)
  • 原文地址:https://www.cnblogs.com/shineqiujuan/p/1301341.html
Copyright © 2011-2022 走看看