Bind DropDownList SelectedValue from Enum
<p>I have enum for Salutation like</p>

<pre><code>public enum SALUTATION
{
    MR = 1,
    MS = 2,
    MRS = 3,        
}
</code></pre>

<p>and in my <code>staff</code> class my <code>Salutation</code> property is like,</p>

<pre><code>public SALUTATION Salutation
{
     get;
     set;
}
</code></pre>

<p>here, while editing the staff profile am just binding the datas from the database. For salutation I just tried binding the salutation like</p>

<pre><code>ddlSalutation.SelectedValue = Enum.GetName(typeof(SALUTATION), staff.Salutation);
</code></pre>

<p>but it binds the selectedValue as <code>-1</code> always. how can I bind the exact value in the ddl selected item. can anyone help me here..</p>

<p>in the page load event am just binding the ddl source as</p>

<pre><code> Hashtable hashSalutation = Utilities.GetEnumList(typeof(SALUTATION));
            ddlSalutation.DataSource = hashSalutation;
            ddlSalutation.DataTextField = "value";
            ddlSalutation.DataValueField = "key";
            ddlSalutation.DataBind();

            ddlSalutation.Items.Insert(0, new ListItem("Select Salutation", "-1"));

public Hashtable GetEnumList(Type enumeration)
    {
        string[] names = Enum.GetNames(enumeration);
        Array values = Enum.GetValues(enumeration);
        Hashtable ht = new Hashtable();
        for (int i = 0; i &lt; names.Length; i++)
        {
            ht.Add(Convert.ToInt32(values.GetValue(i)).ToString(), names[i]);
        }
        return ht;
    }
</code></pre>
