Suppose I have a months enum like the below:

enum MonthName{Jan = 1,Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec }

My objective is to get the month name(MMM) from integer value,
e.g If I have 1 then Jan should be returned from the above enum.

string strTemp = “1”;
MonthName mnthName = (MonthName)Convert.ToInt32(strTemp);
string strname= Enum.GetName(typeof(MonthName), mnthName);

So by using GetName, it retrieves the name of the constant in the specified enumeration that has the specified value.

So, strname returns Jan as the input value was 1.

In ASp.NET grids, doing this is very easy, suppose you want to display the date as ‘Apr – 2009’, you just need to modify the DataFormatString property of the grid as 
DataFormatString=”{0:MMM – yyyy}”

Advertisements