Binding DropDownList Sorted List in asp.net

MyList:
<asp:DropDownList ID="ddlist" runat="server" DataSource='<%# mylist%>' DataTextField="value" DataValueField="key" ></asp:DropDownList>


In Code Behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

public partial class test : System.Web.UI.Page
{
   protected  SortedList mylist;
  
    protected void Page_Load(object sender, EventArgs e)
    {
      
            mylist = new SortedList();
            mylist.Add(1, "Pooja");
            mylist.Add(2, "priya");
            if (!IsPostBack)
            {
                ddlist.DataBind();
              
            }


    }
Ebook Download
View all
Learn
View all