使用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 />

    <asp:button />

    <br /><br />

    <b>Definition: </b>

    <asp:Label />

  </form>

</html>

原文地址:http://linglong117.blog.163.com/blog/static/27714547200901235551137/

相关文章:

  • 2021-07-08
  • 2022-12-23
  • 2022-12-23
  • 2021-12-15
  • 2021-12-15
  • 2021-08-19
  • 2021-12-15
猜你喜欢
  • 2021-12-15
  • 2021-12-15
  • 2021-10-05
  • 2021-12-15
  • 2021-10-15
相关资源
相似解决方案