Showing posts with label Enum. Show all posts
Showing posts with label Enum. Show all posts

Sunday, July 11, 2010

Using Enum in Javascript


<script type="text/javascript" language="javascript">
var enumTabInfo = {
BasicInformation: 1,
SkillDetail: 2,
EducationDetail: 3,
ProjectDetail: 4,
CompanyDetail: 5
}

$(document).ready(function(){
$("div.UserTab").Hide();

var intTabNo = Number($("#<%= hdnCurrentTab.ClientID %>").val());

switch (intTabNo) {
case enumPageStep.BasicInformation:
$("#divBasicInformation").show();
break;

case enumPageStep.SkillDetail:
$("#divSkillDetail").show();
break;

case enumPageStep.EducationDetail:
$("#divEducationDetail").show();
break;

case enumPageStep.ProjectDetail:
$("#divProjectDetail").show();
break;

case enumPageStep.CompanyDetail:
$("#divCompanyDetail").show();
break;
}
});
</script>

Saturday, July 10, 2010

Enum Extention

Enum Extention :

public static class EnumExtention
{
public static Dictionary<int, string> GetEnumData(this Type EnumType)
{
Dictionary<int, string> objEnumList = new Dictionary<int, string>();

if (EnumType != null && EnumType.IsEnum)
{
foreach (int intCount in Enum.GetValues(EnumType))
{
objEnumList.Add(intCount, Enum.GetName(EnumType, intCount).ToString().Replace("_", " "));
}
}
return objEnumList;
}
}
Get Enum Data :

private enum enumUserType
{
Admin,
Sales_Department,
Purchase_Department,
Guest
}

protected void Page_Load(object sender, EventArgs e)
{
ddlUserType.DataSource = typeof(enumUserType).GetEnumData();

ddlUserType.DataTextField = "Value";
ddlUserType.DataValueField = "Key";

ddlUserType.DataBind();
}
Output :

<select name="ddlUserType" id="ddlUserType">
<option value="1">Admin</option>
<option value="2">Sales Department</option>
<option value="3">Purchase Department</option>
<option value="4">Guest</option>
</select>