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>
  • 相关阅读:
    RMQ
    LCA 笔记
    LUCAS 定理
    topcoder 643 DIV2
    BZOJ 1071组队
    Codeforces Round #283 (Div. 2)
    topcoder 642
    Codeforces Round #278 (Div. 2)
    树链剖分
    Codeforces Round #277 (Div. 2)
  • 原文地址:https://www.cnblogs.com/kokoliu/p/517625.html
Copyright © 2011-2022 走看看