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>
  • 相关阅读:
    hdu2151
    hdu1028
    hdu1398
    hdu1465
    hdu2853
    poj2195
    poj2255
    JS正则校验数字,特殊字符,邮箱基本格式
    JS正则校验数字,特殊字符,邮箱基本格式
    io读取文件内容乱码处理
  • 原文地址:https://www.cnblogs.com/kokoliu/p/517625.html
Copyright © 2011-2022 走看看