zoukankan      html  css  js  c++  java
  • 遍历SortedList集合元素——使其顺序按字母排序(汉字则按拼音首字母排序)

    郁闷,昨天发了居然被我误删了,今天重新再发。
    使用SortedList集合对象,方便的对DropdownList控件的下来列表元素进行按字母排序,汉字则按拼音首字母排序,这个功能还不错。
    SortedList.aspx

    <%@Page Language="c#" debug="true"  %>

    <script runat="server" Language="c#">

      
    void Page_Load(object source, EventArgs e)

      
    {

        SortedList mySortedList 
    = new SortedList();

        mySortedList[
    "张三"]="我是张三";

        mySortedList[
    "李四"]="我是李四";

        mySortedList[
    "王五"]="我是王五";

        mySortedList[
    "赵六"]="我是赵六";

        
    if (!(Page.IsPostBack))

        
    {

          
    foreach (DictionaryEntry Item in mySortedList)

          
    {

            ListItem newListItem 
    = new ListItem();

            newListItem.Text 
    = Item.Key.ToString();

            newListItem.Value 
    = Item.Value.ToString();

            myDropDownList.Items.Add(newListItem);

          }


        }


      }


      
    void Click(object source, EventArgs e)

      
    {

        myLabel.Text 
    = myDropDownList.SelectedItem.Value;

      }


    </script>

    <html>

      
    <form runat="server">

        Pick a word from the list:

        
    <asp:dropdownlist id="myDropDownList" runat="server" />

        
    <asp:button id="myButton" runat="server" text="OK" Onclick="Click" />

        
    <br /><br />

        
    <b>Definition: </b>

        
    <asp:Label id="myLabel" runat="server" text="" />

      
    </form>

    </html>
  • 相关阅读:
    78. Subsets
    93. Restore IP Addresses
    71. Simplify Path
    82. Remove Duplicates from Sorted List II
    95. Unique Binary Search Trees II
    96. Unique Binary Search Trees
    312. Burst Balloons
    程序员社交平台
    APP Store开发指南
    iOS框架搭建(MVC,自定义TabBar)--微博搭建为例
  • 原文地址:https://www.cnblogs.com/kokoliu/p/517625.html
Copyright © 2011-2022 走看看