Monday, 25 February 2013

example of enum

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

public partial class _Default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
      
        if (!IsPostBack)
        {
            foreach (int i in Enum.GetValues(typeof(x)))
            {
                ListItem li = new ListItem();
                li.Text = Enum.GetName(typeof(x), i);
                li.Value = i.ToString();
                ddl.Items.Add(li);
            }

            foreach (int i in Enum.GetValues(typeof(y)))
            {
                ddl.Items.Add(Enum.GetName(typeof(y),i));
            }
          
        }
    }

    protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
    {
        Response.Write(ddl.SelectedValue.ToString());
    }
}
public enum x
{
    a=1,
    b=3,
    c=5,
    d=9
}
public enum y
{
    select,
    x,
    y,
    z
}

No comments:

Post a Comment