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>
  • 相关阅读:
    luogu_1168: 中位数
    luogu_4762: [CERC2014]Virus synthesis
    luogu_4287:双倍回文
    回文自动机学习笔记
    luogu_3645: 雅加达的摩天楼
    python爬今日头条(ajax分析)
    Python多进程multiprocessing.Pool()
    Python爬微博(ajax+mongo)
    python实用函数之join()
    python之tuple与list
  • 原文地址:https://www.cnblogs.com/kokoliu/p/517625.html
Copyright © 2011-2022 走看看