Use SortedList (C#) : SortedList « Collections « ASP.Net






Use SortedList (C#)

<%@Page Language="c#" debug="true"  %>
<script runat="server" Language="c#">
  void Page_Load(object source, EventArgs e)
  {
    SortedList mySortedList = new SortedList();
    mySortedList["a"]="aa";
    mySortedList["b"]="bb";
    mySortedList["c"]="cc";
    mySortedList["d"]="dd";
    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>

           
       








Related examples in the same category

1.SortedList Demo (VB.net)
2.Sorted List Demo (C#)