Here is the sample for using enum for comparison with numeric value. See the highlighted lines for using a enum comparison in switch case:
you can use this aspx page's code behind file to test in your aspx page, for this you have to make the following changes Inherits in aspx page:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestPage.aspx.cs" Inherits="Code4Green.FreeCodeGenerationTool.TestPage" %>
SAMPLE
using System;
using System.Web.UI.HtmlControls;
namespace Code4Green.FreeCodeGenerationTool
{
public partial class TestPage :
System.Web.UI.Page
{
public enum FilterByDoctorType
{
General,
Dental,
Orthopadic,
ENT,
Cancer
}
protected void
Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.Controls.Add(CreateDoctorContextControls(0,111011));
this.Controls.Add(CreateDoctorContextControls(1,
111011));
this.Controls.Add(CreateDoctorContextControls(2,
111011));
this.Controls.Add(CreateDoctorContextControls(3,
111011));
this.Controls.Add(CreateDoctorContextControls(4,
111011));
}
}
private HtmlGenericControl
CreateDoctorContextControls(int filterByValue, int doctorId)
{
HtmlGenericControl htmlStudentListItemControl = new HtmlGenericControl();
switch (filterByValue)
{
case ((int)FilterByDoctorType.General):
htmlStudentListItemControl = CreateYourWebControl(doctorId,"General Physician. "); break;
case ((int)FilterByDoctorType.Dental):
htmlStudentListItemControl = CreateYourWebControl(doctorId,"Dental Surgon. "); break;
case ((int)FilterByDoctorType.ENT):
htmlStudentListItemControl = CreateYourWebControl(doctorId,"ENT Specialist. "); break;
case ((int)FilterByDoctorType.Orthopadic):
htmlStudentListItemControl = CreateYourWebControl(doctorId,"Orthopadic surgon. "); break;
case ((int)FilterByDoctorType.Cancer):
htmlStudentListItemControl = CreateYourWebControl(doctorId,"Cancer Specialist. "); break;
default:
htmlStudentListItemControl = CreateYourWebControl(doctorId,"General Physician"); break;
}
return htmlStudentListItemControl;
}
private HtmlGenericControl
CreateYourWebControl(int doctorId,string yourText)
{
HtmlGenericControl divControl = new HtmlGenericControl("div");
HtmlGenericControl hyperlinkControl = new HtmlGenericControl("a");
hyperlinkControl.Attributes.Add("href",
"http://www.code4green.com");
hyperlinkControl.Attributes.Add("class",
"yourCSS.Class");
hyperlinkControl.Attributes.Add("title",
"Plant a free tree by using code4green
website");
hyperlinkControl.InnerText = "goto
code4green website";
HtmlGenericControl spanControl = new HtmlGenericControl("span");
spanControl.Attributes.Add("class",
"MySpanClass");
spanControl.InnerText =yourText;
divControl.Controls.Add(spanControl);
divControl.Controls.Add(hyperlinkControl);
return divControl;
}
}
}
No comments:
Post a Comment